C++ 使用I/O时出错

C++ 使用I/O时出错,c++,io,C++,Io,因此,我有一个非常基本的代码,应该可以工作,但是,我经常遇到两个错误: 1. Method 'open' could not be resolved. 2. Method 'close' could not be resolved. 我对C++还不熟悉,但我已经看到它在其他地方被大量使用,但它对我来说不起作用。有人能给我解释一下到底发生了什么事吗?代码如下: #include <iostream> #include <fstream> using namespace s

因此,我有一个非常基本的代码,应该可以工作,但是,我经常遇到两个错误:

1. Method 'open' could not be resolved.
2. Method 'close' could not be resolved.
我对C++还不熟悉,但我已经看到它在其他地方被大量使用,但它对我来说不起作用。有人能给我解释一下到底发生了什么事吗?代码如下:

#include <iostream>
#include <fstream>
using namespace std;

int main() {

    ofstream myfile;
    myfile.open ("example.txt");
    myfile << "Writing this to a file.\n";
    myfile.close();
    return 0;

}
#包括
#包括
使用名称空间std;
int main(){
流文件;
myfile.open(“example.txt”);

我的文件你是如何编译的?你使用的是任何特定的IDE吗?哦,对不起。我使用的是Eclipse Mars。好的,如果它对你来说工作正常,那么它一定是IDE出了问题。这很奇怪,但我通过关闭Eclipse并重新打开它来工作。