Read text line by line without escape character

Hello,

I am trying to read texts in a file line by line.
Example:
Line 1: Text1\nText2

here I am readingh this line using fgets/getline for 255 character.
But in the result I am getting an extra "\" appended for each "\"
so the line which I am reading above is coming as

Text1\\nTExt2.

I am now printing this text which is coming as Text1\\nTExt2 instead of
Text1
Text2

Hwo can I avoid this extra "\" coming while reding the text.

Code snap:

ifstream in(fileName);
if (!in)
{
cout << "Cannot open input file.\n";
}

char str[255];

while (in)
{
in.getline(str, 255); // delim defaults to '\n'
if (in) cout << str << endl;
}

in.close();
The escape sequences like \n only apply in string literals (strings in quotes within your program). When you read a line from a file, you get exactly what's there. So if the file contains a backslash followed by the letter 'n' then the string that you read will contain a backslash followed by the letter 'n', not a single newline character.
I don't think it will produce an extra backslash \. I have testing in a program as below:

int main()
{
using namespace std;

string data("/tmp/test.txt");


ifstream in(data.c_str());
if (!in.is_open()) return 1;
string line;


while (getline(in, line)) {
std::cout << line << std::endl;
}

}

my text.txt file contains:
test\ntest
test1\ntest1

And the out put as below, no extra \
test\ntest
test1\ntest1
Topic archived. No new replies allowed.