0

I'm doing a homework from school in C++. Currently, I'm doing an exercise of creating a system of books library.

Everything is working perfectly, but if I type something with accents, the input didn't work very well...

void searchBook() {
     std::string title;
     cout << "Book name: " << endl;
     std::getline(std::cin >> std::ws, title); // this will get book name, even with whitespaces
     cout << title;
     ...
}

For example: If I type: "O senhor dos anéis", the "cout << title" will show: "O senhor dos an'eis" on console.

How can I solve it? Thank you.

korn
  • 109
  • 7
  • [How to print UTF-8 strings to std::cout on Windows?](https://stackoverflow.com/questions/45575863/how-to-print-utf-8-strings-to-stdcout-on-windows) – Max Vollmer Sep 29 '19 at 21:22
  • [Properly print utf8 characters in windows console](https://stackoverflow.com/questions/10882277/properly-print-utf8-characters-in-windows-console) – Max Vollmer Sep 29 '19 at 21:22
  • [How do I print UTF-8 from c++ console application on Windows](https://stackoverflow.com/questions/1371012/how-do-i-print-utf-8-from-c-console-application-on-windows) – Max Vollmer Sep 29 '19 at 21:22
  • Even if you are not on Windows, the answers on those questions should provide you with enough information to fix this. – Max Vollmer Sep 29 '19 at 21:23
  • I guess that the issue is not related to cout, because I'm comparing cin with an vector, and the result is: not found => https://pastebin.com/tGTqREs9 – korn Sep 29 '19 at 21:34
  • `if (final[i].titulo == title) {` results in not found because the accent is not being inserted correctly – korn Sep 29 '19 at 21:36
  • The cause for encoding issues between console and application apply equally to cin and cout, so that doesn't really matter. – Max Vollmer Sep 29 '19 at 21:37
  • Do you know an effective and crossplatform way to fix it? Because I'm doing it on Windows and I need show it on linux at my school – korn Sep 29 '19 at 21:52
  • Don't add code in links, screenshots or comments. Edit and add the code directly to the question. – Trenton McKinney Sep 29 '19 at 22:04
  • 3
    Possible duplicate of [How to print UTF-8 strings to std::cout on Windows?](https://stackoverflow.com/questions/45575863/how-to-print-utf-8-strings-to-stdcout-on-windows) – Trenton McKinney Sep 29 '19 at 22:06
  • I cannot use Windows library even I'm using Windows right now, because this project will be executed on Linux. I already said this above – korn Sep 29 '19 at 22:18

0 Answers0