473,569 Members | 3,015 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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::ostringstr eam ss;
ss << stData.cFileNam e << "\r\n";

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

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

stData.cFileNam e is a char buffer.

Angus
Jun 18 '07 #1
6 4480
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::ostringstr eam ss;
ss << stData.cFileNam e << "\r\n";

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

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

stData.cFileNam e is a char buffer.
You probably need to post this question to a Microsoft newsgroup.
There is no such thing as "compilatio n 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::ostringstr eam ss;
[ For OP (just an idea, I don't know) ]
On the C++ side:

A std::ostringstr eam '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_ostringst ream : public basic_ostream<_ CharT, _Traits>
{ /* .... */ };

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

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

std::ostringstr eam< 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::ostringstr eam< wchar_t ss;

Please let us know if it works.

std::cout<<" sizeof(wchar_t) ="<<sizeof(wcha r_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::ostringstr eam< wchar_t ss;

Please let us know if it works.
That's

std::basic_ostr ingstream<wchar _tss;

or

std::wostringst ream ss;
>
std::cout<<" sizeof(wchar_t) ="<<sizeof(wcha r_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.c omwrote:
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::ostringstr eam ss;
std::ostringstr eam 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::wostringst ream.
ss << stData.cFileNam e << "\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.cFileNam e << "\r\n";

}

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

stData.cFileNam e 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.********@com Acast.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::ostringstr eam< wchar_t ss;

Please let us know if it works.

That's

std::basic_ostr ingstream<wchar _tss;

or

std::wostringst ream 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
6194
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 (prerelease) ===========================================
6
3005
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 << "\"\" \"\"" << outfilename << "\"\""; //line 75
5
2354
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: std::ostringstream::ostringstream(const std::string&) Gives some weird results on both Solaris & Linux. Either that or I'm missing something. I've made a simple program to
2
5669
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 seen commercial programs print output to the screen as well as to a log file. depending on the user and other situations, i might want to turn off...
3
5589
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
2368
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 make me doubt that. Can I depend on the behavior of something like this? ostringstream os; os.write("This is a test.", strlen("This is a...
15
1921
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 " << 12.33 << " and a number";
1
8112
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 string str; str << ... << ...; SomeAPI( str.c_str() );
11
3629
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 tried a std::ostringstream: std::ostringstream oss; oss << x << y << z; std::string result ( oss.str() ); The result shows that feeding the...
0
7703
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6290
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5228
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3662
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1229
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.