Sunday, July 12, 2009

C++ I/0 Question?

Hi, my friend asked me, the neighborhood computer guy, for some C++ help. Sadly, I have never used C++. I could do it in C# or regular C or Java... but anyway, here's the text of his request:





"In C++, I was just wondering how you can read in a text file like:


(name) 45 34 6 3 2


(name2) 54 76 3 4 5


...


I need the name to be a char and the numbers to be ints."

C++ I/0 Question?
std::fstream f("file");





char* name, name2;


int i%26lt;1%26gt;-i%26lt;whatever%26gt;


f%26gt;%26gt;name%26gt;%26gt;i%26lt;whatever;





f.close();





you will have to #include%26lt;fstream%26gt; and %26lt;iostream%26gt;.
Reply:No, iostream is not required when you've already included fstream...Rest is OK...


No comments:

Post a Comment