stl getline question

Started by
0 comments, last by nitzan 21 years, 2 months ago
I have the following piece of code:

	std::vector vec1;
	std::string line;
	vec1.clear();

	ifstream infile("textfile.txt");

	while (std::getline(infile,line,''\n'')) {
		vec1.push_back (line);
	}
 
For some reason I get the following compiler error: error C2784: ''class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &,const _E)'' : could not deduce template argument for ''class std::basic_istream<_E,_Tr> &'' from ''class ifstream'' Anyone have any ideas ? If I take away the std:: reference for getline, I get the error: error C2065: ''getline'' : undeclared identifier Nitzan ------------------------- www.geocities.com/nitzanw www.scorchedearth3d.net -------------------------
Advertisement
You need to include some missing declarings.


  #include <iostream>#include <vector>#include <string>using std::string;#include <fstream>using std::ifstream;std::vector<string> stringData;string theString;ifstream inFile;inFile.open("someFile.txt", ios::in);while (std::getline(inFile, theString))   stringData.push_back(theString);  


Kuphryn


This topic is closed to new replies.

Advertisement