![]() |
| ||
| vc++ mfc-i can't make getline work with a string for file input i'm trying to use getline to read from a file into a std::string and when i give it the normal 2 parameters (my ifstream and the string) the compiler says it wants 3 arguments , but when i give it 3 it says it wants 2 arguments. this makes absolutly no sense to me! plus i can't imagine what third parameter getline could possibly need anyway. heres a snippit just to illustrate: #include <fstream> am i retarded? or is the compiler... |
| ||
| Re: vc++ mfc-i can't make getline work with a string for file input >> ccin.open(data.dat); I think you mean ccin.open("data.dat");>> getline(ccin,str);//the problem :(Looks okay to me. What compiler are you using? Can you give us a short and complete program to compile that gives you the error? Can you post the error? |
| ||
| Re: vc++ mfc-i can't make getline work with a string for file input Quote:
(cust.cpp) // Cust.cpp : Defines the class behaviors for the application. THESE are the errors i get with the above code: C:\Documents and Settings\Dave\Desktop\Cust\Cust.cpp(91) : error C2784: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &)' : could not deduce template argument for 'class std::basic_istream<_E,_Tr> &' from 'class ifstream' C:\Documents and Settings\Dave\Desktop\Cust\Cust.cpp(91) : error C2780: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &,const _E)' : expects 3 arguments - 2 provided c:\program files\microsoft visual studio\vc98\include\string(149) : see declaration of 'getline' Error executing cl.exe. I tried adding "30" as a third argument, but i just get the same errors only it says expected 2 arguments - 3 provided NOTE: SORRY I COULDN'T UPLOAD THE FILE IT WAS A LITTLE TOO LARGE SO I'LL JUST MAKE A NEW PROGRAM AND REALLY QUICK AAND POST IT WHEN ITS DONE the compiler i'm using is whatever one comes with ms visual c++ 6.0 thanks in advance |
| ||
| Re: vc++ mfc-i can't make getline work with a string for file input >> #include <fstream.h> Mixing old and new headers will bite you every time. #include <fstream>That's why it's a good idea to cut and paste the code you have from the start rather re-type it in the post. |
| ||
| Re: vc++ mfc-i can't make getline work with a string for file input Quote:
thank you sooo much!! What do you mean old and new... is <fstream.h> different than <fstream>? |
| ||
| Re: vc++ mfc-i can't make getline work with a string for file input >> is <fstream.h> different than <fstream>? Yes, very different. <fstream> is a standard modification of the prestandard <fstream.h>, where all of the classes are turned into template classes and a bunch of other relatively minor changes are made. Unless you're forced to write legacy code on a legacy system, always use the standard headers. You can tell them apart because the standard headers don't have a .h extension. |
| ||
| Re: vc++ mfc-i can't make getline work with a string for file input okay thanks |
| All times are GMT -4. The time now is 6:16 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC