我正在尝试获取一个程序来读取.txt文件,但是它返回了不可读的信息。任何建议或帮助将不胜感激。
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main() {
fstream file;
file.open("/Users/Arrakis/Downloads/Toppings.txt");
string toppings;
if (!file)
{
cout << "File opening error!" << endl;
}
getline(file, toppings);
while (file) {
cout << toppings << endl;
getline(file, toppings);
}
file.close();
return 0;
}
返回的数据是:
{\rtf1\ansi\ansicpg1252\cocoartf2511
\cocoatextscaling0\cocoaplatform0{\fonttbl\f0\fswiss\fcharset0
Helvetica;}
{\colortbl;\red255\green255\blue255
{\*\expandedcolortbl;;}\margl1440\margr1440\vieww10800\viewh8400
\viewkind0\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320
\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural\
partightenfactor0
\f0\fs24 \cf0 Pepperoni\
Ham\
Pineapple\
Veggies}
需要重新格式化.txt文件,使其不包含.rtf元素。