By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,605 Members | 1,483 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,605 IT Pros & Developers. It's quick & easy.

Unicode

P: n/a

I want to write a C++ prog in Unicode.
int main(void)
{

cout << L"Hello!";

}
Anyone got any suggestions?!

Thanks
Jul 22 '05 #1
Share this Question
Share on Google+
13 Replies


P: n/a

"JKop" <NU**@NULL.NULL> wrote in message
news:vc******************@news.indigo.ie...

I want to write a C++ prog in Unicode.
int main(void)
{

cout << L"Hello!";

}
Anyone got any suggestions?!

Thanks


You might have more luck if you use wcout instead of cout, but C++ has no
specific support for Unicode.

john
Jul 22 '05 #2

P: n/a
John Harrison posted:

"JKop" <NU**@NULL.NULL> wrote in message
news:vc******************@news.indigo.ie...

I want to write a C++ prog in Unicode.
int main(void)
{

cout << L"Hello!";

}
Anyone got any suggestions?!

Thanks
You might have more luck if you use wcout instead of cout, but C++

has no specific support for Unicode.

john


Thanks,

Where can I get "wcout"?
Jul 22 '05 #3

P: n/a

"JKop" <NU**@NULL.NULL> wrote in message
news:Ix******************@news.indigo.ie...
John Harrison posted:

"JKop" <NU**@NULL.NULL> wrote in message
news:vc******************@news.indigo.ie...

I want to write a C++ prog in Unicode.
int main(void)
{

cout << L"Hello!";

}
Anyone got any suggestions?!

Thanks


You might have more luck if you use wcout instead of cout, but C++

has
no specific support for Unicode.

john


Thanks,

Where can I get "wcout"?


From the iostream header file.

#include <iostream>

int main()
{
std::wcout << L"hello world\n";
}

john
Jul 22 '05 #4

P: n/a
I'm getting 434a4.
what it does?
John Harrison wrote:

"JKop" <NU**@NULL.NULL> wrote in message
news:vc******************@news.indigo.ie...

I want to write a C++ prog in Unicode.
int main(void)
{

cout << L"Hello!";

}
Anyone got any suggestions?!

Thanks


You might have more luck if you use wcout instead of cout, but C++ has no
specific support for Unicode.

john

Jul 22 '05 #5

P: n/a

"myName" <my******@myweb.com> wrote in message
news:40***************@myweb.com...
I'm getting 434a4.
what it does?


That's probably the address of the string. Compiler support for Unicode or
even for wide characters often isn't very good. For more help I'd recommend
asking on a newsgroup that supports your particular compiler. They'll be
able to tell you what compiler specific stuff you have to do.

John
Jul 22 '05 #6

P: n/a
On Thu, 22 Apr 2004, JKop wrote:

I want to write a C++ prog in Unicode.


You could also overload operator<< for wide character strings.

#include <iostream>
#include <cwchar>

/* stream inserter for wide character strings */
std::ostream&
operator<<(std::ostream& os, const wchar_t* wcs)
{
size_t len = std::wcslen(wcs) + 1;
len *= 2; //assumption: length(mbs) <= 2 * length(wcs)
char* mbs = new char[len];
std::wcstombs(mbs, wcs, len);
os << mbs;
delete [] mbs;
return os;
}

This method has worked fine for me. But if you can use std::wcout, then
prefer it to the code given above. (Even if one has to use std::cout,
this code could be improved since we traverse the wide string twice.
Any suggestions?)

--
Claudio Jolowicz
http://www.doc.ic.ac.uk/~cj603

Jul 22 '05 #7

P: n/a
Claudio Jolowicz posted:
On Thu, 22 Apr 2004, JKop wrote:

I want to write a C++ prog in Unicode.

You could also overload operator<< for wide character strings.

#include <iostream>
#include <cwchar>

/* stream inserter for wide character strings */
std::ostream&
operator<<(std::ostream& os, const wchar_t* wcs)
{
size_t len = std::wcslen(wcs) + 1;
len *= 2; //assumption: length(mbs) <= 2 * length(wcs)
char* mbs = new char[len];
std::wcstombs(mbs, wcs, len);
os << mbs;
delete [] mbs;
return os;
}

This method has worked fine for me. But if you can use std::wcout,

then prefer it to the code given above. (Even if one has to use std::cout, this code could be improved since we traverse the wide string twice. Any suggestions?)

The thing is that I need Unicode!! I want to display Arabic currency!

-JKop
Jul 22 '05 #8

P: n/a
>You could also overload operator<< for wide character strings.

[snip my code multiplying string length by 2]

Better use MB_LEN_MAX to compute maximum length of string.

#include <iostream>
#include <cwchar>

/* stream inserter for wide character strings */
std::ostream&
operator<<(std::ostream& os, const wchar_t* wcs)
{
size_t len = std::wcslen(wcs) + 1;
len *= MB_LEN_MAX;
char* mbs = new char[len];
std::wcstombs(mbs, wcs, len);
os << mbs;
delete [] mbs;
return os;
}

int main()
{
std::cout << L"Hello." << std::endl;
return 0;
}

--
Claudio Jolowicz
http://www.doc.ic.ac.uk/~cj603

Jul 22 '05 #9

P: n/a
>

The thing is that I need Unicode!! I want to display Arabic currency!

-JKop


C++ has no built in support for Unicode. Are you prepared to buy a third
party library that gives you that support? Are you working on a operating
system that supports Unicode?

Unless the answers to both those questions are yes, then I don't think you
are going to get very far. As I said before the best place to ask about this
is not a C++ group, because C++ has no support for Unicode.

So try again on a group that supports whatever combination of operating
system and compiler you are using. Have a look here for suggestions
http://www.slack.net/~shiva/welcome.txt

john
Jul 22 '05 #10

P: n/a
"JKop" <NU**@NULL.NULL> wrote in message
news:uu******************@news.indigo.ie...
The thing is that I need Unicode!! I want to display Arabic currency!


In that case, you'd better be sure you're using the right
codecvt facet when you perform wide I/O. See our CoreX
library for the tools that are missing from Standard C++.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
Jul 22 '05 #11

P: n/a
"John Harrison" <jo*************@hotmail.com> wrote in message news:<c6************@ID-196037.news.uni-berlin.de>...
"JKop" <NU**@NULL.NULL> wrote in message
news:Ix******************@news.indigo.ie...
John Harrison posted:

"JKop" <NU**@NULL.NULL> wrote in message
news:vc******************@news.indigo.ie...
>
> I want to write a C++ prog in Unicode.
>
>
> int main(void)
> {
>
> cout << L"Hello!";
>
> }
>
>
> Anyone got any suggestions?!
>
> Thanks

You might have more luck if you use wcout instead of cout, but C++ has no specific support for Unicode.

john


Thanks,

Where can I get "wcout"?


From the iostream header file.

#include <iostream>

int main()
{
std::wcout << L"hello world\n";
}

john


Just a general heads-up here ... I think you also have to have some
sort of local OS-level support for Unicode for that to work. For
example, I use g++ on cygwin, and my compiler does not recognize wcout
as a member of the std namespace. I looked at the <iostream> header,
and it has an #ifdef block around the std::wcout declaration that
"hides" it when there is no wchar support on my system, which is
apparently true in my case.

HTH, Dave Moore
Jul 22 '05 #12

P: n/a
Dave Moore wrote:

Just a general heads-up here ... I think you also have to have some
sort of local OS-level support for Unicode for that to work. For
example, I use g++ on cygwin, and my compiler does not recognize wcout
as a member of the std namespace. I looked at the <iostream> header,
and it has an #ifdef block around the std::wcout declaration that
"hides" it when there is no wchar support on my system, which is
apparently true in my case.


Well, somebody's confused. wchar_t is part of the C and C++ languages.
The encoding used for wchar_t doesn't have to be Unicode. std::wcout is
part of the standard C++ library. The C and C++ standards don't make
these things dependent on the OS, so if your compiler doesn't provide
them it doesn't conform to those standards.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Jul 22 '05 #13

P: n/a

"JKop" <NU**@NULL.NULL> wrote in message
news:vc******************@news.indigo.ie...

I want to write a C++ prog in Unicode.
int main(void)
{

cout << L"Hello!";

}
Anyone got any suggestions?!

Thanks


if you mean making your code translatable to different programming
languages, you could just substitute cout with output

function main
output "Hello!"

something like that
Jul 22 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.