目前正在嘗試使用我創建的 C 讀取文本檔案,并讓它回圈顯示單詞。我試過使用 fstream 和 istream 但由于某種原因我仍然收到這個錯誤說
HarlemRenaissance.txt:1:1: error: ‘The’ does not name a type
1 | The Harlem Renaissance was an intellectual
有誰知道可能是什么問題?
這是我的代碼的一個片段:
#include <iostream>
#include <fstream>
#include <stdio.h>
#include "HarlemRenaissance.txt"
using namespace std;
int main() {
//reads file
// Create a text string, which is used to output the text file
string myText;
// Read from the text file
std::ifstream MyReadFile("HarlemRenaissance.txt");
// Use a while loop together with the getline() function to read the file line by line
while (std::getline (MyReadFile,myText)) {
// Output the text from the file
std::cout << myText << std::endl;
}
//output data
outputStats();
//closes file
MyReadFile.close();
}
uj5u.com熱心網友回復:
#include "HarlemRenaissance.txt"從您的代碼中洗掉。實際上包括意味著復制粘貼。包含檔案的內容將粘貼在源檔案中。在這種情況下,您的檔案內容將粘貼到您的源代碼中。也許它有一些語法不正確的詞。這就是您收到此錯誤訊息的原因。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/374257.html
