473,836 Members | 1,480 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to output the wchar_t type string


int main()
{
wchar_t p[]="Good Morning";
}

How to use cout on p.
That is, can I use cout<<p;

It's not working.

Can anybody suggest how to use cout on wchar_t type strings?

Thanks
Vignesh

May 23 '06 #1
7 31017

"abbu" <vi********@red iffmail.com> wrote in message
news:11******** **************@ i39g2000cwa.goo glegroups.com.. .

int main()
{
wchar_t p[]="Good Morning";
}

How to use cout on p.
That is, can I use cout<<p;

It's not working.

Can anybody suggest how to use cout on wchar_t type strings?


int main() {
wchar_t p[]="Good Morning";
std::wcout << p;
}

Mostly when it comes to wide strings you just use the normal funcs but add
"w" to the start.
eg.:

const char *str = "text";
printf(str);

const wchar_t *str = "text";
wprintf(str);

cout outputs a standard byte stream (ansi)
wcout outputs a wide stream (e.g. unicode)

//eric
May 23 '06 #2
abbu <vi********@red iffmail.com> wrote:
int main()
{
wchar_t p[]="Good Morning";
}

How to use cout on p.
That is, can I use cout<<p;

It's not working.

Can anybody suggest how to use cout on wchar_t type strings?


The following program works fine here:
#include <iostream>

int main()
{
wchar_t p[] = L"Good Morning";
std::wcout << p << '\n';
}

--
Marcus Kwok
Replace 'invalid' with 'net' to reply
May 23 '06 #3
After posting this i noticed that i made bad usage of printf and wprintf.

In case some people new to programming sees this, i better point out that
this is bad:

char *str = "text";
printf(str);

If str has "%s" inside it will crash the app.

Correct usage:

char *str = "text";
printf("%s", str);

//eric
May 23 '06 #4
* Marcus Kwok:
abbu <vi********@red iffmail.com> wrote:
int main()
{
wchar_t p[]="Good Morning";
}

How to use cout on p.
That is, can I use cout<<p;

It's not working.

Can anybody suggest how to use cout on wchar_t type strings?


The following program works fine here:
#include <iostream>

int main()
{
wchar_t p[] = L"Good Morning";
std::wcout << p << '\n';
}


g++ 3.4.4 on Windows does not support wide character streams.

Also be aware that what the wide characters streams do, is to convert to
narrow characters, in some /unspecified/ way.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
May 23 '06 #5
Alf P. Steinbach <al***@start.no > wrote:
* Marcus Kwok:
The following program works fine here:
#include <iostream>

int main()
{
wchar_t p[] = L"Good Morning";
std::wcout << p << '\n';
}


g++ 3.4.4 on Windows does not support wide character streams.

Also be aware that what the wide characters streams do, is to convert to
narrow characters, in some /unspecified/ way.


I guess I should have mentioned that this was using VC++ 7.1 (VS .NET
2003) on Windows XP.

Thanks for the info regarding wide streams. I never use them but this
example seemed easy enough to whip together.

--
Marcus Kwok
Replace 'invalid' with 'net' to reply
May 23 '06 #6
abbu wrote:
int main()
{
wchar_t p[]="Good Morning";
}


You need an L ahead of the text literal to make it wide.

May 23 '06 #7
Thanks eric.

May 24 '06 #8

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

Similar topics

3
2988
by: Julius Mong | last post by:
Hi all, I'm doing this: // Test char code wchar_t lookup = {0x8364, 0x5543, 0x3432, 0xabcd, 0xef01}; for (int x=0; x<5; x++) { wchar_t * string = (wchar_t*) malloc(sizeof(wchar_t)); string = (wchar_t*)lookup; string = '\0'; CComBSTR bstrTest = SysAllocString(string); }
6
4225
by: Sumpfman | last post by:
Hi there, i really got stuck on working with this. The user should be able to set his usr_delay as argument and later on i want to do some math with this (adding usr_delay to the time i get from the NetRemoteTOD function) so i need to convert the userinput to int. int wmain(int argc, wchar_t *argv) {
11
5226
by: Roger Leigh | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 The program listed below demonstrates the use of wcsftime() and std::time_put<wchar_t> which is a C++ wrapper around it. (I know this isn't C; but the "problem" lies in the C library implementation of wcsftime()). I'm not sure if this is a platform-dependent feature or part of the C standard. I've compiled with GCC 3.4.3 on GNU/Linux, and run in an en_GB UTF-8
23
8209
by: Steven T. Hatton | last post by:
This is one of the first obstacles I encountered when getting started with C++. I found that everybody had their own idea of what a string is. There was std::string, QString, xercesc::XMLString, etc. There are also char, wchar_t, QChar, XMLCh, etc., for character representation. Coming from Java where a String is a String is a String, that was quite a shock. Well, I'm back to looking at this, and it still isn't pretty. I've found...
7
1413
by: sonu | last post by:
Hi all, from my code i want the out put should be 502 but its giving 7 pls any one try to correct. (Actualy i want to write a similar function as atol() which takes const char * and gives long but i need my function should take const wchar_t * and returns long.) #include<stdlib.h> int main() {
0
1023
by: Jose Cintron | last post by:
I have a program that reads an XML file and extract a specific filed from the file. The filed is "free" form text, here's an example === start example text Ensure that individual users are not setup with the option password never expires. If any accounts listed in the user report have a "No" in the "PswdExpires" column, then this is a finding.
3
3704
by: Angus | last post by:
I can see how to get a char* but is it possible to get a wide char - eg wchar_t?
4
9807
by: interec | last post by:
Hi Folks, I am writing a c++ program on redhat linux using main(int argc, wchar_t *argv). $LANG on console is set to "en_US.UTF-8". g++ compiler version is 3.4.6. Q1. what is the encoding of data that I get in argv ? Q2. what is encoding of string constants defined in programs (for example L"--count") ?
5
17052
by: yakir22 | last post by:
Hello experts, I am dealing now in porting our server from windows to linux. our client is running only on windows machine. to avoid the wchar_t size problem ( in windows its 2 bytes and linux is 4 bytes ) we defined #ifdef WIN32 #define t_wchar_t wchar_t #else // LINUX #define t_wchar_t short
0
9668
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10840
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10546
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10588
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10254
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9371
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6978
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
4013
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3112
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.