I have a school project that requires me to load a text file that includes UTF-8 characters like "ł,ą,ż,ź,ć,...", and then to do some editing on that text.
The problem is that, if I use SetConsoleOutputCP(65001), it loads the file correctly, but then if I try to use cin with ł, ą, etc then the characters disappear.
#include <iostream>
#include <fstream>
#include <string>
#include<windows.h>
using namespace std;
string opfile(string name){
string line;
ifstream myfile (name);
string tekst;
if (myfile.is_open())
{
while(getline(myfile, line)) {
tekst += line + "\n";
}
myfile.close();
}
else cout << "Unable to open file";
return tekst;
};
int main() {
SetConsoleOutputCP(65001);
string file_name;
cin >> file_name;
cout << opfile(file_name);
string cos;
cin >> cos;
cout << cos;
return 0;
}
This is whats inside the text file
ŁŁŁŁŁŁŁŁĄĄĄĄĄĄĄĄĄĄĄÓÓÓÓĆÓŹŻÓŹĆŹŻÓĆŻÓźćÓÓÓĆŹÓŻĆŻÓŹĆÓŚĄŚĄÓÓĄŚÓŚĄÓÓŚÓŚĄ
If I try to input this later, nothing is outputted.
I tried looking around, but everyone says the SetConsoleOutputCP() should work.