I'm writing a program which processes some data, outputs it to a .csv file, then writes a GNUplot script, and calls GNUplot to execute the script and create an image file all with the same name (only different extensions). The filenames contain UTF characters (UTF-8 I believe?) such as °, φ and θ. All of this works perfectly fine when I compile and execute it in Linux with g++ 4.4.7. I then altered my code to compile in Microsoft Visual Studio 2008, and the problems start when I run the program.
I use the following two bits of code to
- Make a standard filename string (to which I just add extensions for the various files)
Open a stream to write to a file (the only difference between the GNUplot script and the .csv files is the extensions
// Generate a file name string stringstream ss; ss << type << " Graph #" << gID << " - " << title; string fileName = ss.str(); // Open a stream for the output file ostringstream outfile; outfile << fileName << ".gplt" << ends; ofstream ofs( outfile.str().c_str() );
The contents of the ofstream
files where ofs
writes contain the UTF characters properly, however the stringstream-created string fileName
and the ostringstream
created filename (even when not created with fileName
, I tested it) show the characters incorrectly.
Example:
What it should be - CDFvsRd Graph #32 - MWIR @ 300m, no-sun, 30kts, θ=all°.csv
What it ends up as - CDFvsRd Graph #32 - MWIR @ 300m, no-sun, 30kts, Ï=allË.csv
What can I do to remedy this, with as much standard C++ as possible? Would converting my fileName
string to wstring
help?