473,386 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

ostringstream Unicode problem

Sorry about the platform specific code here, but I include to show what I am
doing. I am trying to create a char* directory listing.

If I compile the code below as Unicode then I get memory addresses in
strResponse. But it works fine if not compiled with Unicode. How would I
edit the code to work under Unicode?

WIN32_FIND_DATA stData;
//do first find call
HANDLE hReturn = ::FindFirstFile(TEXT("C:\\*.*"), &stData);
if (hReturn == INVALID_HANDLE_VALUE) return -1;

std::ostringstream ss;
ss << stData.cFileName << "\r\n";

while (::FindNextFile( hReturn, &stData))
{
ss << stData.cFileName << "\r\n";
}

FindClose(hReturn);
std::string strResponse = ss.str();

stData.cFileName is a char buffer.

Angus
Jun 18 '07 #1
6 4463
Angus wrote:
Sorry about the platform specific code here, but I include to show
what I am doing. I am trying to create a char* directory listing.

If I compile the code below as Unicode then I get memory addresses in
strResponse. But it works fine if not compiled with Unicode. How
would I edit the code to work under Unicode?

WIN32_FIND_DATA stData;
//do first find call
HANDLE hReturn = ::FindFirstFile(TEXT("C:\\*.*"), &stData);
if (hReturn == INVALID_HANDLE_VALUE) return -1;

std::ostringstream ss;
ss << stData.cFileName << "\r\n";

while (::FindNextFile( hReturn, &stData))
{
ss << stData.cFileName << "\r\n";
}

FindClose(hReturn);
std::string strResponse = ss.str();

stData.cFileName is a char buffer.
You probably need to post this question to a Microsoft newsgroup.
There is no such thing as "compilation as Unicode" defined in C++
language Standard. I believe it's compiler- and platform-specific.
Check out FAQ section 5 for the list of the suggested newsgroups.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 18 '07 #2

Victor Bazarov wrote in message... [snipped]
Angus wrote:
If I compile the code below as Unicode then I get memory addresses in
strResponse. But it works fine if not compiled with Unicode. How
would I edit the code to work under Unicode?

std::ostringstream ss;
[ For OP (just an idea, I don't know) ]
On the C++ side:

A std::ostringstream 'defaults' to 'char'.
It will need to be passed the parameters of the Unicode for it to be used.

The 'footprint' is (from <sstream>):

template <typename _CharT, typename _Traits, typename _Alloc>
class basic_ostringstream : public basic_ostream<_CharT, _Traits>
{ /* .... */ };

Fill in the [ ]s, at bare minimum fill in the first one:
std::ostringstream< [Unicode char], [traits], [allocator] ss;

If you don't know and can't find the info, you might try:

std::ostringstream< wchar_t ss;

[ Thanks for the use of your post, Victor. ]
--
Bob R
POVrookie
Jun 19 '07 #3

BobR wrote in message...

Just checked the wxWidgets docs. They say Unicode is two-bytes wide (wchar_t
type), so, the following line should be the one used.

std::ostringstream< wchar_t ss;

Please let us know if it works.

std::cout<<" sizeof(wchar_t) ="<<sizeof(wchar_t)<<std::endl;
// out: sizeof(wchar_t) =2
--
Bob R
POVrookie
Jun 19 '07 #4
BobR wrote:
BobR wrote in message...

Just checked the wxWidgets docs. They say Unicode is two-bytes wide
(wchar_t type), so, the following line should be the one used.

std::ostringstream< wchar_t ss;

Please let us know if it works.
That's

std::basic_ostringstream<wchar_tss;

or

std::wostringstream ss;
>
std::cout<<" sizeof(wchar_t) ="<<sizeof(wchar_t)<<std::endl;
// out: sizeof(wchar_t) =2
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 19 '07 #5
On Jun 19, 4:16 am, "Angus" <nos...@gmail.comwrote:
Sorry about the platform specific code here, but I include to show what I am
doing. I am trying to create a char* directory listing.

If I compile the code below as Unicode then I get memory addresses in
strResponse. But it works fine if not compiled with Unicode. How would I
edit the code to work under Unicode?

WIN32_FIND_DATA stData;
//do first find call
HANDLE hReturn = ::FindFirstFile(TEXT("C:\\*.*"), &stData);
if (hReturn == INVALID_HANDLE_VALUE) return -1;
Microsoft pushes the idea that _T and and their TEXT macros is all the
difference that you need for Windows Unicode and Windows narrow
character support. Unfortunately it isn't true (although it was more
nearly so before they started to use the standard C++ libraries).
>
std::ostringstream ss;
std::ostringstream is for char. If you want to compiler for both
Unicode and narrow characters then you'll need to use conditional
compilation to determine the correct type. For wchar_t this needs to
be std::wostringstream.
ss << stData.cFileName << "\r\n";
You will also need to use the TEXT or _T macros here (can't remember
which does what as I don't use them I'm afraid).

ss << ... << _T( "\r\n" );
>
while (::FindNextFile( hReturn, &stData))
{
ss << stData.cFileName << "\r\n";

}

FindClose(hReturn);
std::string strResponse = ss.str();

stData.cFileName is a char buffer.
This will need to change between char and wchar_t depending on how
you're compiling it.

This is all very fidlly. Why are you even bothering with narrow
character support? On Windows it seems pointless these days. If you're
going to the bother of supporting Unicode compilation then just use
that throughout and forget about narrow character support.

You can still use narrow characters where you need to interact with
legacy systems and to handle formats that are specified as 7/8 bit
characters.
K

Jun 19 '07 #6

Victor Bazarov <v.********@comAcast.netwrote in message...
BobR wrote:
Just checked the wxWidgets docs. They say Unicode is two-bytes wide
(wchar_t type), so, the following line should be the one used.

std::ostringstream< wchar_t ss;

Please let us know if it works.

That's

std::basic_ostringstream<wchar_tss;

or

std::wostringstream ss;
Pick one:
a) Doooh, I can't believe I did that.
b) Duh, my brain went on strike.
c) all of the above.

Thanks for the correction, Victor.

--
Bob R
POVrookie
Jun 19 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Alex Vinokur | last post by:
Is it possible to use vector<ostringstream> ? Here is what I have got. =========================================== Windows 2000 CYGWIN_NT-5.0 1.3.22(0.78/3/2) GNU gcc version 3.2 20020927...
6
by: Eric Boutin | last post by:
Hi ! I have a strange problem with a std::ostringstream.. code : #include <sstream> /*...*/ std::ostringstream ss(); ss << "\"\"" << libpath << "\"\" \"\"" << argfilename << "\"\"...
5
by: Simon Pryor | last post by:
I am having some strange problems using std::ostringstream. The simple stuff works okay, but trying to use: std::ostringstream::str(const std::string&) or:...
2
by: Julian | last post by:
I would like to have output from my program to be written to cout as well as a file. (actually, i want several other output options but this should explain my problem in the simplest way). I have...
3
by: Mathieu Malaterre | last post by:
Hello, I am trying to write this simple code: std::ostringstream s; s << 1024; std::cout << s.str() << std::endl; s.str(""); // <- problem s << 512; std::cout << s.str() << std::endl;
10
by: roberts.noah | last post by:
Using ostringstream the buffer gets increased to allow data to be appended when needed at least when you call <<. I was under the impression that write() also did but I am having problems that...
15
by: iu2 | last post by:
Hi all, can someone help me with this? I'm trying to shorthen some logging function in our project, i.e., instead of LogString("...); use a more convenient log() << "String here " <<...
1
by: schoedl | last post by:
Hello, we often compose strings via a ostringstream and then create a string from it. What is the rationale of not being able to use string in place of a ostringstream, so I could write ...
11
by: coomberjones | last post by:
I have a few std::strings that I am using to store raw binary data, each of which may very well include null bytes at any point or points. I want to slap them together into a single string, so I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.