Console not displaying certain characters

Hi everyone, could use some help here.

I am writing a program pulling data from a .txt file; the program will get more complicated, but the problem I am having is that when I pull the text:

“The artist never entirely knows — We guess. We may be wrong, but we take leap after leap in the dark” ~Agnes de Mille

My console displays this correctly but the quotation marks and dash are displayed by strange characters.

Here is my code. Any help would be greatly appreciated!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <fstream>
#include <string>

#include <cstdlib>
#include <ctime>

using namespace std;

int main() {

    string quote;

    ifstream inFS;
    inFS.open("quotes.txt");
    getline(inFS, quote);

    cout << quote;

}
You probably created the quote.txt file with a program, non dos command.

Change your quote to read:

"The artist never entirely knows - We guess. We may be wrong, but we take leap after leap in the dark" ~Agnes de Mille


SamuelAdams - Thanks for the reply.

The problem with changing the quotes is that my program will be reading a long list of quotes from a .txt file not made by me but sent to me.

My professor wants us to use the .txt that he has provided. It is a long list of quotes, each on a separate line, and my program is reading from that file a displaying it in the console.

I was wondering if there was any way for my console to display the characters in the .txt file exactly as they are without having to edit the .txt file myself.

Again thank you for the reply!
I was wondering if there was any way for my console to display the characters in the .txt file exactly as they are

Linux console displays them exactly as they are, since it supports Unicode everywhere. I bet you're on Windows, which makes these things complicated and there isn't enough information to say how to fix it. What exactly were the "strange characters"? What encoding does the file use? what version of visual studio do you compile that with? etc.
Yes, I am on windows 10. I'm using CodeBlocks for my IDE and the GNU GCC Compiler.

The console is displaying ΓÇ¥ instead of quotation marks, and ΓÇÖ for apostrophes. I'm pretty sure the .txt file was written in notepad but I am not sure because everyone is linking the same file our professor provided.

Thanks for the help, not sure it's absolutely necessary to fix this but curious as to what the problem is.

The console is displaying ΓÇ¥

The character ” is RIGHT DOUBLE QUOTATION MARK (U+201D)
Its UTF-8 encoding is 0xE2 0x80 0x9D - that's the correct way to store it in a text file.
"ΓÇ¥" is how those three bytes appear when displayed as MS-DOS code page 437, the original IBM PC single-byte encoding from 1981. This leads me to believe that your Windows console is configured for that code page (or one of its variants)

I've only ever used Visual Studio on Windows, which has a couple different ways to fix this, but I am sure a search for "How to print UTF-8 file in Code Blocks" will turn something up.
Last edited on
Topic archived. No new replies allowed.