When writing a program, I'm having issues working with a combination of special characters and regular ones. When I print either type to the console separately, they work fine, but when I print a special and normal character in the same line, it results in errored characters instead of the expected output. My code:
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
void initCharacterMap(){
const string normal = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890!@#$%^&*()-_[]{};':\",.<>/?";
const string inverse = "∀Ↄ◖ƎℲ⅁HIſ⋊⅂WᴎOԀΌᴚS⊥∩ᴧMX⅄Zɐqɔpǝɟƃɥıɾʞʃɯuodbɹsʇnʌʍxʎz12Ɛᔭ59Ɫ860¡@#$%^⅋*)(-‾][}{؛,:„'˙></¿";
cout << normal << endl;
for(int i=0;i<normal.length();i++){
cout << normal[i];
}
cout << endl;
cout << inverse << endl;
for(int i=0;i<inverse.length();i++){
cout << inverse[i];
}
cout << endl;
for(int i=0;i<inverse.length();i++){
cout << normal[i] << inverse[i] << endl;
}
}
int main() {
initCharacterMap();
return 0;
}
And the console output: https://paste.ubuntu.com/p/H9bqh67WPZ/
When viewed in console, the \XX characters show up as unknown character symbol, and when I opened that log, I was warned that some characters couldn't be viewed and that editing could corrupt the file.
If anyone has any advice on how I can fix this, it would be greatly appreciated.
EDIT: After following the suggestion in Marek R's answer, the situation greatly improved, but this still isn't quite giving me the results I want. New code:
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
void initCharacterMap(){
const wchar_t normal[] = L"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890!@#$%^&*()-_[]{};':\",.<>/?";
const wchar_t inverse[] = L"∀Ↄ◖ƎℲ⅁HIſ⋊⅂WᴎOԀΌᴚS⊥∩ᴧMX⅄Zɐqɔpǝɟƃɥıɾʞʃɯuodbɹsʇnʌʍxʎz12Ɛᔭ59Ɫ860¡@#$%^⅋*)(-‾][}{؛,:„'˙></¿";
wcout << normal << endl;
for(int i=0;i<sizeof(normal)/sizeof(normal[0]);i++){
wcout << normal[i];
}
wcout << endl;
wcout << inverse << endl;
for(int i=0;i<sizeof(inverse)/sizeof(inverse[0]);i++){
wcout << inverse[i];
}
wcout << endl;
for(int i=0;i<sizeof(inverse)/sizeof(inverse[0]);i++){
wcout << normal[i] << inverse[i] << endl;
}
}
int main() {
initCharacterMap();
return 0;
}
New console output: https://paste.ubuntu.com/p/hcM7JB99zj/
So, I'm no longer having issues with using output of contents of the strings together, but the issue with it now is that all non-ascii characters are being replaced with question marks in the output. Is there any way to make those characters output properly?