Click here to Skip to main content
15,892,575 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Question Regarding Template in C++ Pin
Christian Graus28-Jun-05 19:06
protectorChristian Graus28-Jun-05 19:06 
GeneralAdding Folder Paths Pin
Member 171940628-Jun-05 17:51
Member 171940628-Jun-05 17:51 
GeneralRe: Adding Folder Paths Pin
22491728-Jun-05 18:25
22491728-Jun-05 18:25 
GeneralRe: Adding Folder Paths Pin
Blake V. Miller29-Jun-05 19:16
Blake V. Miller29-Jun-05 19:16 
QuestionWhats Wrong for calling convention? Pin
lewislewis_lewis28-Jun-05 13:48
lewislewis_lewis28-Jun-05 13:48 
AnswerRe: Whats Wrong for calling convention? Pin
Rick York28-Jun-05 14:59
mveRick York28-Jun-05 14:59 
AnswerRe: Whats Wrong for calling convention? Pin
Cedric Moonen28-Jun-05 20:35
Cedric Moonen28-Jun-05 20:35 
GeneralTransparent Unicode/Ascii using STL Pin
Patje28-Jun-05 12:32
Patje28-Jun-05 12:32 
In my application I want to access files, where the underlying character type (ASCII or Unicode) is transparent for the application.

Suppose that in a reporting module a report is written to file, like this:
myfile << reportHeader << std::endl;
for (all columns) myfile << columnname;
myfile << std::endl;
for (all records)
   {
   for (all columns) myfile << data;
   myfile << std::endl;
   }


Now, I want my application to transparently write the report to ASCII or Unicode files, depending on the user specification.
Currently, you have to do it like this:
std::ofstream asciiFile;
std::wofstream unicodeFile;
if (user wants Unicode)
   {
   unicodeFile.open ("output.txt");
   unicodeFile << reportHeader << std::endl;
   }
else
   {
   asciiFile.open ("output.txt");
   asciiFile << reportHeader << std::endl;
   }
for (all columns) 
   {
   if (user wants Unicode) unicodeFile << columnname;
   else                    asciiFile << columnName;
   }
... and so on


The disadvantages seem obvious:
- clumsy, unreadable code (especially if the write-to-file logic is spread over several methods)
- writing Unicode strings (std::wstring) to an Ascii stream doesn't even work; it produced garbage

Therefore, I need a kind of transparent stream, so that I can write the following:
transparentstream myfile;
myfile.setMode (ascii or unicode);
myfile.open ("output.txt");
myfile << reportHeader << std::endl;
for (all columns) myfile << columnname;
myfile << std::endl;
for (all records)
   {
   for (all columns) myfile << data;
   myfile << std::endl;
   }


Problems are:
- from which stream do I inherit the transparentstream?
- how do I define the transparentstream so all defined output operators keep on working?
- where do I put the conversion logic? (basic_buf? basic_filebuf?)

Of course I want something similar for input, where the stream can find out itself whether the file is Unicode (starts with 0xfffe or 0xfeff) or plain Ascii.

And as an additional challenge: is it possible to have such a transparent stream that can do something like this?
transparentstream mystream;
mystream.open("http://www.mywebsite.com/mypage.html");
mystream >> ...;

And if this is possible, how do I implement such a stream of buf class?

Did some of you already encounter problems trying to mix the STL and Unicode files?
How did you solve it?

Probably Java and .Net solve this problem in a elegant way, but I really need a solution using only STL.

Thanks for you suggestions.

Enjoy life, this is not a rehearsal !!!



Enjoy life, this is not a rehearsal !!!

GeneralRe: Transparent Unicode/Ascii using STL Pin
John R. Shaw29-Jun-05 9:04
John R. Shaw29-Jun-05 9:04 
Generalwindow enumeration from pid Pin
c. s.28-Jun-05 12:29
c. s.28-Jun-05 12:29 
GeneralRe: window enumeration from pid Pin
Blake Miller28-Jun-05 12:50
Blake Miller28-Jun-05 12:50 
Generaldevice arrival message Pin
Ann6628-Jun-05 12:17
sussAnn6628-Jun-05 12:17 
General,device arrival message Pin
Anonymous28-Jun-05 12:11
Anonymous28-Jun-05 12:11 
GeneralBegin_message_map Pin
kongy7928-Jun-05 9:40
kongy7928-Jun-05 9:40 
GeneralRe: Begin_message_map Pin
David Crow28-Jun-05 10:35
David Crow28-Jun-05 10:35 
GeneralRe: Begin_message_map Pin
kongy7928-Jun-05 14:12
kongy7928-Jun-05 14:12 
QuestionHow to version a DLL generated by Message Compiler ? Pin
jlarsj28-Jun-05 9:39
jlarsj28-Jun-05 9:39 
QuestionHow do you Monitor a Windows Service? Pin
Rodney Sullivan28-Jun-05 7:56
Rodney Sullivan28-Jun-05 7:56 
AnswerRe: How do you Monitor a Windows Service? Pin
Blake Miller28-Jun-05 12:40
Blake Miller28-Jun-05 12:40 
GeneralRe: How do you Monitor a Windows Service? Pin
Rodney Sullivan29-Jun-05 4:52
Rodney Sullivan29-Jun-05 4:52 
GeneralRe: How do you Monitor a Windows Service? Pin
Blake Miller29-Jun-05 5:24
Blake Miller29-Jun-05 5:24 
GeneralRe: How do you Monitor a Windows Service? Pin
Rodney Sullivan29-Jun-05 5:59
Rodney Sullivan29-Jun-05 5:59 
GeneralRe: How do you Monitor a Windows Service? Pin
Blake Miller29-Jun-05 6:12
Blake Miller29-Jun-05 6:12 
GeneralRe: How do you Monitor a Windows Service? Pin
Rodney Sullivan29-Jun-05 7:31
Rodney Sullivan29-Jun-05 7:31 
GeneralRe: How do you Monitor a Windows Service? Pin
Blake Miller29-Jun-05 7:52
Blake Miller29-Jun-05 7:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.