2

I have a text file (ANSI) that contains accent characters, for example:

A
àà
ééc

I'm unable get the accent characters to show and to manipulate with.

This is my code:

ifstream readfile(argv[1]); // to read a text file
string output;

while (!readfile.eof())
{
    getline(readfile, output);
    const char *p = output.c_str(); 

    while (*p != '\0')
    {
        //Some of my codes here for manipulation, comparison...
        cout << *p++;
    }
    cout << endl;
}

I did some research and I also tried wcout, wifstream, wstring, wchar_t, but they don't seem to work... I also notice the "getline" is unable to read accent characters.

With a text file without any accent characters, my current code works perfectly.

When there is an accent character, it shows a strange character instead and because of that, I'm unable to do some manipulation.

EDIT:

With const char *p, I'm unable to assign the accent characters to do comparisons in the program itself.

What I'm really trying to do is getting the accent characters from the text file, and then do some comparison inside the program/code, and when the comparison is over, it writes the correct output in a new text file.

The input and output text files show the correct accent characters. The real issue is I want to compare the accent characters in the program/code itself.

EDIT2:

For example,

My input for the const char *p is "à". In my program, I use the p (which is "à", but it shows ▒ instead) to compare "à", the result is suppose to be true, but it gives me false.

"à" compare with "à" should be true.

but in my program, instead, it's

"▒" compare with "à", and it's false.

Lord Rixuel
  • 1,173
  • 6
  • 24
  • 43
  • 2
    There are many ways of encoding the characters in a text file, ASCII, MBCS, UTF-8, UTF-16BE, UTF-16LE, etc. What's the encoding of the file you are trying to read? If it is one of the Unicode formats does it include a BOM (byte order mark)? – Richard Critten Jul 13 '16 at 16:59
  • But when you read a text file, you will get them, just as a char array it won't always visualize the characters. Your code is alright in that sense. – Noam Rodrik Jul 13 '16 at 17:06
  • 1
    There is no "ANSI" character set. There is 7-bit ASCII, and then there are Windows code pages. For a text file, you have to know the character encoding in order to make sense of it. – stark Jul 13 '16 at 17:08
  • try posting code for the comparison... – user673679 Jul 13 '16 at 17:14

0 Answers0