簡體   English   中英

在 Visual Studio 19 中無法識別 ofstream 和 ifstream 的錯誤

[英]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.

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