For Programmers: Free Programming Magazines  


Home > Archive > VC Language > November 2005 > VC8: streams and locales









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author VC8: streams and locales
Josué Andrade Gomes

2005-11-24, 7:01 pm

Hi,

Take this code:

#include <sstream>
#include <cassert>
#include <locale>

int main()
{
std::istringstream iss;
iss.str("{1,}");

char ch;
int n;

iss >> ch;
iss >> n; // works on vc7.1, fail on vc8
assert(!iss.fail());
iss >> ch;
}

apparently the locale being used by istringstream on vc8 is using a grouping
configuration of 3. On vc7.1 the configuration is 0.
I solved this by doing:

class my_numpunct : public std::numpunct_byname<char> {
public:
my_numpunct (const char *name)
: std::numpunct_byname<char>(name) {}
protected:
virtual std::string do_grouping() const {
return "";
}
};

And then

iss.imbue(std::locale(std::locale(""), new my_numpunct("")));

Is this the correct solution?

regards,
Josue
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com