[英]Error with ofstream and ifstream being unidentified in Visual Studio 19
我正在嘗試使用文件創建程序,當我使用 ofstream 或 ifstream 時,Visual Studio 說 ofstream 和 ifstream 是未定義的。 有人可以解釋一下嗎?
#include <iostream>
#include <fstream>
int main()
{
ofstream file("Test.txt", std::ios::app);
file << "File successfully made\n";
file.close();
return 0;
}
即使這根本不起作用。
ofstream
位於命名空間std
中,因此您需要指定它。
#include <iostream>
#include <fstream>
int main()
{
std::ofstream file("Test.txt", std::ios::app); // ofstream -> std::ofstream
file << "File successfully made\n";
file.close();
return 0;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.