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

What's wrong with this programe?

P: n/a
#include<iostream>
#include<fstream>
using namespace std;
void main()
{
wchar_t str="hh";
wcout<<str;
}

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


P: n/a
"Michael" <wi****@sina.com> wrote in message
news:bp**********@news.yaako.com...
#include<iostream>
#include<fstream>
You're not using anything from header <fstream>
using namespace std;
void main()
int main()
{
wchar_t str="hh";
wchar_t str = L"hh";
wcout<<str;
std::wcout << str << L'\n';

return 0; /* optional, but 'good style' */
}


-Mike
Jul 22 '05 #2

P: n/a

"Mike Wahler" <mk******@mkwahler.net> wrote in message
news:PA*****************@newsread1.news.pas.earthl ink.net...
"Michael" <wi****@sina.com> wrote in message
news:bp**********@news.yaako.com...
#include<iostream>
#include<fstream>


You're not using anything from header <fstream>
using namespace std;
void main()


int main()
{
wchar_t str="hh";


wchar_t str = L"hh";


wchar_t str[] = L"hh";

-Mike
Jul 22 '05 #3

P: n/a
"Michael" <wi****@sina.com> writes:
#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;
}
--------------------

--
Micah J. Cowan
mi***@cowan.name
Jul 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.