In case you happen to use other compilers, here's a bit of exposure on how this works across platforms
First, of all, simplifying the example:
1 2 3 4 5
|
#include <iostream>
int main()
{
std::cout << "Total Sales for book £" << 10 << '\n';
}
|
On Unicode-friendly OS's, such as Linux, this works as written:
http://ideone.com/IdbyLh
The standard, portable C++ approach is to use wide streams, since '£' is not an ASCII character:
1 2 3 4 5 6 7 8
|
#include <iostream>
#include <locale>
int main()
{
std::locale::global(std::locale("en_US.utf8")); // any unicode works
std::wcout.imbue(std::locale());
std::wcout << L"Total Sales for book £" << 10 << '\n';
}
|
This works on any OS that has standard Unicode support of C and C++:
http://ideone.com/q63Mvr
Windows has no standard Unicode support, so you have to resort to OS-specific API calls to get anything done. I would avoid touching console codepages for being too incompatible with the rest of the world. You can actually use standard C++, only the magic words to turn on wcout are different:
1 2 3 4 5 6 7 8 9
|
#include <iostream>
#include <fcntl.h>
#include <io.h>
using namespace std;
int main()
{
_setmode(_fileno(stdout), _O_WTEXT);
std::wcout << L"Total Sales for book £" << 10 << '\n';
}
|
tested on Visual Studio 2012, I don't have C::B