Re: isspace
On 28 Jan, 21:25, gervaz <ger...@gmail.com> wrote:
On Jan 28, 9:40 pm, Paavo Helde <myfirstn...@osa.pri.ee> wrote:
gervaz <ger...@gmail.com> wrote in news:198ffd0f-8a21-4d23-802f-
cf0f0fee0...@o28g2000yqh.googlegroups.com:
Hi all, is there a C++ function similar to isspace that
can handle w_chars? Does the regex library handles
w_chars?
Yes, there is a template function declared in <locale> and
named std::isspace, curiously enough.
There is no regex librar in the official C++ standard yet I
think. The Boost regex library is fully templated and ought
to support wchar_t as well, but I have not tried this.
According to Boost documentation one needs a separate ICU
library for full Unicode support though.
Well, take a look at my snippet:
std::ifstream infile(argv[1]);
std::string s;
while (getline(infile, s))
{
s.erase(std::remove_if(s.begin(), s.end(), std::isspace), s.end
());
std::cout << s;
}
Using locale on VC++2008 I've got an error reporting that
std::isspace expects 2 arguments,
That's because std::isspace requires two arguments, the
character to be tested, and the locale.
and still I don't know if the file contains unicode characters
can be correctly handles.
The functions in <locale> are pretty useless, since they only
handle single byte characters. The "approved" solution is to
read into a wstring using wifstream (embedded with the
appropriate locale), and use isspace (again with the appropriate
locale) on the wchar_t in the wstring.
--
James Kanze