As the previous poster mentioned, you can use stringstreams to convert ints to strings and vise versa, but with C++11 there are some new features that eliminate the need to do this. You can use std::to_string or std::to_wstring to convert ints to strings or wstrings, and you can use c_str() to get the raw char* or wchar_t* from the string object. You should be able to convert the appropriate type of pointer to your winapi string, but some can depend on your compiler's settings.
For your reference, here's what the winapi strings mean:
LPSTR = char*
LPCSTR = const char*
LPWSTR = wchar_t*
LPCWSTR = const wchar_t*
LPTSTR = char* or wchar_t* depending on _UNICODE
LPCTSTR = const char* or const wchar_t* depending on _UNICODE
And here is a quick sample of how to assign them to C++ strings:
#include <iostream>
#include <string>
#include <Windows.h>
#include <tchar.h>
int main()
{
// Declare winapi strings
LPSTR str_charPtr;
LPCSTR str_constCharPtr;
LPWSTR str_wcharPtr;
LPCWSTR str_constWcharPtr;
LPTSTR str_tcharPtr;
LPCTSTR str_constTcharPtr;
// Declare a test integer
int num = 5001;
// Convert the integer to a string and to a wstring
std::string regString = std::to_string(num);
std::wstring wideString = std::to_wstring(num);
// Attempt to assign the winapi strings to the C++ standard strings
str_charPtr = const_cast<char*>(regString.c_str()); // NOTE: removing const to store in non-const LPSTR
str_constCharPtr = regString.c_str();
str_wcharPtr = const_cast<wchar_t*>(wideString.c_str()); // NOTE: removing const to store in non-cost LPWSTR
str_constWcharPtr = wideString.c_str();
str_tcharPtr = const_cast<TCHAR*>(regString.c_str()); // Error if set to Unicode
str_tcharPtr = const_cast<TCHAR*>(wideString.c_str()); // Error if NOT set to Unicode
str_constTcharPtr = regString.c_str(); // Error if set to Unicode
str_constTcharPtr = wideString.c_str(); // Error if NOT set to Unicde
return 0;
}
If you've moved on to Visual Studio 2012 by now, you can adjust your settings like so:
1. Right-click the project in the solution explorer.
2. Click on Properties.
3. In the left pane under Configuration Properties, select General
4. In the right pane, look in the Project Defaults section.
5. Next to Character Set, choose Unicode or whichever option is appropriate for you.