首页 文章

不能在Xcode中使用ifstream

提问于
浏览
1

我是C的新手,并且到处研究这个,似乎无法弄清楚如何编译这个并且不知道为什么 . 它适用于Visual C但不适用于Xcode . 错误似乎在输入流上 . 有什么建议?

错误读取 - “未定义模板的隐式实例化'std :: _ basic_ifstream>'

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

int main()
{
    cout  << "The file is providing the data.";
    ifstream myFile("/Users/me/Desktop/somewords.txt"); // * error

    int i;
    string s;
    double d;
    myFile >> i >> s >> d;
    cout << "here is your data " << endl;
    cout << i << endl << s << endl << d << endl;


    return 0;
}

1 回答

  • 6

    你忘了 #include <fstream> ,这个头文件实际上定义了你所有的 ifstream 善良 . 你包括 <iostream> 两次(或至少试过),也许其中一个本来是 <fstream>

相关问题