1

I'm trying to use stringstreams for getting ints into a string. I do it like this:

std::string const DilbertImage::startUrl = "http://tjanster.idg.se/dilbertimages/dil";
std::string const DilbertImage::endUrl = ".gif";

 DilbertImage::DilbertImage(int d)
{
    cal.setDate(d);

    int year, month, date;

    year = cal.getYear();
    month = cal.getMonth();
    date = cal.getNumDate();

    std::stringstream ss;

    ss << year << "/";

    if(month < 10)
    {
        ss << 0;
    }

    ss << month << "/" << "Dilbert - " << cal.getNumDate() << ".gif";

    filePath = ss.str();

    ss.str("");
    ss.clear();

    ss << startUrl << date << endUrl;

    url = ss.str();

    std::cout << url << '\t' << filePath << std::endl;
}

I expect to get two nice strings that look like this:

url: http://tjanster.idg.se/dilbertimages/dil20060720.gif
filePath: /2006/07/Dilbert - 20060720.gif

But instead when I put the ints in the stringstream they somehow endup getting spaces (or some other blank character inserted in the middle of them) When I paste it from the console window the character shows as a *.

They end up looking like this:

url: http://tjanster.idg.se/dilbertimages/dil20*060*720.gif 
filepath: /2*006/07/Dilbert - 20*060*720.gif

Why is this happening?

Here is the whole project: http://pastebin.com/20KF2dNL

Armandur
  • 55
  • 6

1 Answers1

5

That "*" character is a thousands separator. Someone's been messing with your locale.

This might fix it:

std::locale::global(std::locale::classic());

If you just want to override the numpunct facet (which determines how numbers are formatted):

std::locale::global(std::locale().combine<std::numpunct<char>>(std::locale::classic()));

In your case, when you're setting the swedish locale:

std::locale swedish("swedish");
std::locale swedish_with_classic_numpunct = swedish.combine<std::numpunct<char>>(std::locale::classic());
std::locale::global(swedish_with_classic_numpunct);
Community
  • 1
  • 1
ecatmur
  • 152,476
  • 27
  • 293
  • 366
  • Arrrgh, thanks :) I was using std::locale swedish("swedish"); std::locale::global(swedish);, otherwise VS2010 doesn't ouput åäö correctly. Could I remove the separator somehow but still keep using the locale? – Armandur Jul 11 '12 at 10:34