[英]unable to open a file
我正在嘗試打開文件,一個文本文件。
我包括了string和fstream。
#include <string>
#include <fstream>
這是我程序中的代碼,但是每次我運行該程序時,都會顯示“無法打開文件”。
float unscreen()
{
cout << "Welcome to the screen help area" << endl;
cout << "\n" << endl;
string line;
ifstream myfile("unsreen.txt");
if(myfile.is_open())
{
while(getline(myfile, line))
{
cout << line << '\n';
}
myfile.close();
}
else cout << "unable to open file";
cout << "\n" << endl;
cout << "Press 0 for further action or press 9 to exit." << endl;
我需要更改文件上的內容嗎,我在目錄上找到了文件。
確保您在projects \\ projectname \\ projectname中具有unsreen.txt
相同的代碼工作正常。 如果仍然無法使用,請刪除文件注釋所有代碼並添加
ofstream myfile("unsreen.txt");
myfile<<"sdafe";
myfile.close();
然后打開文件,添加要添加的內容,然后刪除此代碼並替換為較舊的代碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.