I'm using visual c++ 2008. I don't know what namespace system and system::Glob.. are. I've never used "wchar_t" nor Console::Write. Is there a way to display unicode characters with the C++ that was taught to me in school? It looks that ASCII II is supported by using the char datatype while using cout.

#include<iostream>
#include <tchar.h>


using namespace System;
using namespace System::Globalization;
using namespace std;

const char z = 253; 
const wchar_t y = L'\u00b2'; 
int main()
{   

    Console::Write( z );

    cout << endl << z << endl;

    
Console::Write( y );

cout << endl << y << endl;
}

this code displays:
-3
²
²
178
Press any key to continue . . .

Recommended Answers

All 3 Replies

use wcout

#include <iostream>
using namespace std;

int main()
{
	wchar_t buf[] = L"Hello World";

	wcout << buf << L"\n";
}
#include <iostream>
using namespace std;

int main()
{
    wchar_t buf[] = L"²";

    wcout << buf << L"\n";
    return 0 ;
}

outputs ▓

if i Put L'\u00b2' it gives me the same garbage.
I'm using windows 7, i don't know if it's my console, but i suspect, the teachers wouldn't be anybetter. By the way using char super2 = '253' works. I just rather have an option for the future since the ascii characters are rather limited.

#include <iostream>
using namespace std;

int main()
{
    wchar_t buf[] = L"²";

    wcout << buf << L"\n";
    return 0 ;
}

outputs ▓

if i Put L'\u00b2' it gives me the same garbage.
I'm using windows 7, i don't know if it's my console, but i suspect, the teachers wouldn't be anybetter. By the way using char super2 = '253' works. I just rather have an option for the future since the ascii characters are rather limited.

That is because your command line console is not a uni-code application which means the console window you used only can display characters in your locale page. Use wcout to output wchar_t is the right choice.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.