I am trying to get input from the user, with geline. Like so:
1 2
string input = "";
getline(cin,input,'\n');
Then pass it to a funtion that takes a LPCWSTR. Like so:
hr = pVoice->Speak(input, 0, NULL); //Nevermind the usage or the specific funtion
But, I cannot seem to be able to change a string to a LPCWSTR AND use it with getline. I don't see an obvious solution, but I think you guys can help!
Thanks!
The Speak method you are using requires a wide string; that is, a wchar_t pointer. Normal std::string's will give you a char pointer, so you'll have to either widen it to a std::wstring then use the c_str() method or use the ASCII version (if it exists) of the Speak method (probably SpeakA()).
I'm assuming that this method is actually something from the WinAPI. You may also want to look at this article, since I suspect it may contain information related to what you're trying to do here.
It take it that by Speak you mean the ISpVoice::Speak interface method which is part of Microsoft SAPI??
In that case, as it's a COM interface, there is not an ANSI entrypoint.
Have you tried using wcin and wstring instead of cin and string??
1 2 3 4 5 6 7
wstring input; // no need for for = L""; as the constructor
// initializes it to L"" for you
getline(wcin, input); // no need for L'\n' as that's the default
wcout << L"Say : " << input << endl;
hr = pVoice->Speak(input.c_str(), 0, NULL); // still need to use c_str()