Is it possible to read multiple lines of international characters? I can do this with simple ascii strings:
#include <iostream>
#include <string>
void main ()
{
std::string text{};
//I cannot use std::wcin in that manner
//std::wcout << "Enter any arbitrary text terminated by an asterisk:" << std::endl;
//std::wstring wtext{};
//std::getline (std::wcin, wtext, '*');THIS SPECIFIC LINE DOESN'T COMPILE
std::cout << "Enter any arbitrary text terminated by an asterisk:" << std::endl;
std::getline (std::cin, text, '*');
}
How can I achieve the same using a string type that supports international characters?
As requested, I included the line that wouldn't compile. My doubt is: is there another way?
The error is: no instance of overloaded function "std::getline" matches the argument list
Solved. Please note the presence of an L
prefixing '*'
in the accepted answer. In my commented out call to std::getline
using wcin
and wstring
(the one that would generate the compile error) I forgot to use a wchar_t
literal and used a char
literal instead. Thus the types were mismatched (string
is composed of char
, wstring
of wchar_t
- aka wide char). To represent a wide char literal, one needs to add an L
as a prefix, i.e. L'*'
.