Link to home
Start Free TrialLog in
Avatar of hernan007
hernan007

asked on

Reading a file with out of FILE.

Hi experts,

I have the file  data.dat with 2 columns such as this:

12asb24   31niel93
89bhgj83   57yv76
...
32dae56  49jsn01

with N data.
I need read the file using "ifstream" , not FILE .   and store it in a matrix with dimention of N x 2 .

any idea? thanks a lot. !
ASKER CERTIFIED SOLUTION
Avatar of itsmeandnobodyelse
itsmeandnobodyelse
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hernan007
hernan007

ASKER

Hi Alex thanks !!

In order to use the function only is with a call like this?   rigth?

main(){
....
vector<Record> x;
..........
int  val= readData("data.dat", x);
....
Well   I have this error msg   :(

main.cc: In function ‘int readData(const std::string&, std::vector<Record, std::allocator<Record> >&)’:main.cc:38: error: no matching function for call to ‘std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream(<unresolved overloaded function type>)’
/usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/fstream:442: note: candidates are: std::basic_ifstream<_CharT, _Traits>::basic_ifstream(const char*, std::_Ios_Openmode) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/fstream:428: note:                 std::basic_ifstream<_CharT, _Traits>::basic_ifstream() [with _CharT = char, _Traits = std::char_traits<char>]
It needs to be

     ifstream ifs(filename.c_str());

It was a typo.

>>>> with a call like this?   rigth?

Yes, beside that main should have an int type and should return 0   ;-)


Thanks! alex.