无法在Xcode中使用ifstream [英] Cannot use ifstream in Xcode
问题描述
我是C ++的新手,并且到处都在研究它,似乎无法弄清楚如何编译它,也不知道为什么.它可以在Visual C ++中工作,但不能在Xcode中工作.错误似乎在输入流上.有什么建议?
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?
错误读取-未定义模板'std :: _ basic_ifstream>的隐式实例化"
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;
}
推荐答案
您忘记了#include <fstream>
,它实际上是定义所有ifstream
优点的头文件.您两次(或至少尝试过)包含<iostream>
,也许其中一个是<fstream>
?
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>
?
这篇关于无法在Xcode中使用ifstream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!