簡體   English   中英

在 C++ 中讀取文件有困難

[英]Having difficulty with reading files in C++

我試圖讓程序讀取 .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 元素。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM