Cannot use ifstream in Xcode

匿名 (未验证) 提交于 2019-12-03 02:35:01

问题:

I am new to C++ and have researched this everywhere and cannot seem to figure out how to compile this and have not idea why. It works in visual C++ but not Xcode. The error seems to be on the input stream. Any suggestions?

Error reads - "Implicit instantiation of undefined template '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:

You forgot to #include <fstream>, the header file that actually defines all your ifstream goodness. You included <iostream> twice (or at least tried to), perhaps one of those was meant to be <fstream>?



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!