Click here to Skip to main content
15,892,697 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
GeneralRe: Sorry! An error occured while generating the object Pin
Cedric Moonen4-Jul-05 0:53
Cedric Moonen4-Jul-05 0:53 
GeneralATL interop with CLR Pin
squawkbox30-Jun-05 23:28
squawkbox30-Jun-05 23:28 
GeneralRe: ATL interop with CLR Pin
HaniSalehi25-Apr-10 6:57
HaniSalehi25-Apr-10 6:57 
GeneralConversion of C++ templates into C code Pin
Arun Chakaravarthy28-Jun-05 22:30
Arun Chakaravarthy28-Jun-05 22:30 
GeneralRe: Conversion of C++ templates into C code Pin
CP Visitor29-Jun-05 4:14
CP Visitor29-Jun-05 4:14 
GeneralRe: Conversion of C++ templates into C code Pin
Jörgen Sigvardsson29-Jun-05 12:37
Jörgen Sigvardsson29-Jun-05 12:37 
GeneralRe: Conversion of C++ templates into C code Pin
toxcct29-Jun-05 5:53
toxcct29-Jun-05 5:53 
GeneralUnicode streams and ASCII files Pin
Patje28-Jun-05 4:19
Patje28-Jun-05 4:19 
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;<br />
for (all columns) myfile << columnname;<br />
myfile << std::endl;<br />
for (all records)<br />
   {<br />
   for (all columns) myfile << data;<br />
   myfile << std::endl;<br />
   }<br />


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;<br />
std::wofstream unicodeFile;<br />
if (user wants Unicode)<br />
   {<br />
   unicodeFile.open ("output.txt");<br />
   unicodeFile << reportHeader << std::endl;<br />
   }<br />
else<br />
   {<br />
   asciiFile.open ("output.txt");<br />
   asciiFile << reportHeader << std::endl;<br />
   }<br />
for (all columns) <br />
   {<br />
   if (user wants Unicode) unicodeFile << columnname;<br />
   else                    asciiFile << columnName;<br />
   }<br />
... and so on<br />


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;<br />
myfile.setMode (ascii or unicode);<br />
myfile.open ("output.txt");<br />
myfile << reportHeader << std::endl;<br />
for (all columns) myfile << columnname;<br />
myfile << std::endl;<br />
for (all records)<br />
   {<br />
   for (all columns) myfile << data;<br />
   myfile << std::endl;<br />
   }<br />


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;<br />
mystream.open("http://www.mywebsite.com/mypage.html");<br />
mystream >> ...;<br />

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?

Thanks for you suggestions.

Enjoy life, this is not a rehearsal !!!

GeneralRe: Unicode streams and ASCII files Pin
valikac28-Jun-05 11:38
valikac28-Jun-05 11:38 
GeneralRe: Unicode streams and ASCII files Pin
Patje28-Jun-05 12:28
Patje28-Jun-05 12:28 
GeneralRe: Unicode streams and ASCII files Pin
valikac28-Jun-05 12:38
valikac28-Jun-05 12:38 
GeneralRe: Unicode streams and ASCII files Pin
Bobby Mihalca30-Jun-05 22:25
Bobby Mihalca30-Jun-05 22:25 
GeneralRe: Unicode streams and ASCII files Pin
valikac1-Jul-05 8:19
valikac1-Jul-05 8:19 
Generalofstream adding in start of file Pin
SimpleProgramer28-Jun-05 0:56
SimpleProgramer28-Jun-05 0:56 
GeneralRe: ofstream adding in start of file Pin
CP Visitor28-Jun-05 6:57
CP Visitor28-Jun-05 6:57 
GeneralSTL Deque problem...again ! Pin
mmagnani7127-Jun-05 23:27
mmagnani7127-Jun-05 23:27 
GeneralRe: STL Deque problem...again ! Pin
Stuart Dootson28-Jun-05 21:36
professionalStuart Dootson28-Jun-05 21:36 
GeneralRe: STL Deque problem...again ! Pin
mmagnani7128-Jun-05 22:54
mmagnani7128-Jun-05 22:54 
GeneralProblems with toolbar when using TBSTYLE_EX_MIXEDBUTTONS Pin
retro_coder27-Jun-05 21:43
retro_coder27-Jun-05 21:43 
GeneralSTL Notation Pin
Jack Puppy27-Jun-05 17:20
Jack Puppy27-Jun-05 17:20 
GeneralRe: STL Notation Pin
Christian Graus27-Jun-05 18:17
protectorChristian Graus27-Jun-05 18:17 
GeneralRe: STL Notation Pin
Douglas Troy1-Jul-05 7:01
Douglas Troy1-Jul-05 7:01 
Questiondoes BHO have max memory limit? Pin
petevam26-Jun-05 23:11
petevam26-Jun-05 23:11 
AnswerRe: does BHO have max memory limit? Pin
Douglas Troy27-Jun-05 4:47
Douglas Troy27-Jun-05 4:47 
GeneralRe: does BHO have max memory limit? Pin
petevam27-Jun-05 6:20
petevam27-Jun-05 6:20 

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.