質問

I'm new to c++.

I know wchar_t is wide character.

What is wrong in the following code ?? Did i not include the appropriate library ??

#include<iostream.h>
#include<conio.h>
void main()
{
wchar_t *s=L"Hello, World";
cout<<s;
getch();
}

正しい解決策はありません

他のヒント

Simple, stop using Borland Turbo C - it was old when I first pickd up version 3.1 nearly 20 years ago. Turbo C from that era doesn't have a iostream (no extension) file because it was released at a time before the stl was. Prior to that time, the functions were indeed found in iostream.h

As such, I'd expect that it also didn't define wchar_t - I don't even remember if multibyte stuff was around then, unicode certainly wasn't a consideration..

For what it's worth, I've still got a copy of Turbo C on 5 1/4" floppy discs - yes! The floppy floppies... Get a compiler from this century!

Get Code::Blocks with MinGW (~70MB download), or Visual Studio Express (couple hundred), hell - even DevCpp is less archaic than Turbo C.

(Oh, and you've indicated to me that it's overwhelmingly likely your compiler of choice through the inclusion of conio.h)

A number of problems here, though all pretty minor:

#include<iostream.h>

This should be #include <iostream> The standard C++ headers don't have a .h on the end.

void main()

main should return an int, not void.

wchar_t *s=L"Hello, World";
cout<<s;

To write a wide string, you want to use wcout, which is in the std namespace, so this should look like:

std::wcout << s;

Note that getch:

getch();

... is common, but technically not standard, so you can't use it in truly portable code. If you only care about Windows though, that may not be a concern for you.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top