I'm trying to output contents of my text file as strings to the console but I am not getting the desired output. I tried implementing the following but still no luck, any help would be appreciated.
int main() {
ifstream inFile("src/text.rtf");
string line;
while (getline(inFile, line)) {
cout << line << endl;
}
return 0;
}
Text contents:
1
2
3
4
5
6
Output:
{\rtf1\ansi\ansicpg1252\cocoartf1344\cocoasubrtf720
{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
{\colortbl;\red255\green255\blue255;}
\margl1440\margr1440\vieww10800\viewh8400\viewkind0
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\ tx7920\tx8640\pardirnatural
\f0\fs24 \cf0 1\
2\
3\
4\
5\
6}
It is because your inFile
file is not a 'pure' text file, but with the formatting code of Rich Text Format .
Please use notepad.exe to create your inFile
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.