What's wrong with this programe?

M

Michael

#include<iostream>
#include<fstream>
using namespace std;
void main()
{
wchar_t str="hh";
wcout<<str;
}
 
M

Micah Cowan

Michael said:
#include<iostream>
#include<fstream>

You don't use the above header.
using namespace std;
void main()

The only portable declarations for main() return int.
{
wchar_t str="hh";
wcout<<str;
}

The fact that you're assigning a narrow string literal to a wide
/character/ type (not even a string!)

Change str's definition to:

const wchar_t *str = L"hh";

(The const matches the type of the string literal better).

Possibly better would be:

--------------------
#include <iostream>
#include <string>

using namespace std;
int main()
{
wstring str = L"hh";
wcout<<str;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top