Alex Rivera | Logout

Need basic help parsing a string in C++

Asked 2010-02-02T02:51:03.207
14

C++ is not my preferred language.

I have a file that contains this:

e 225,370 35,75

I want to separate e, 225, 370, 35 and 75 from each other into a char and ints but I'm having trouble. I tried doing everything I found online and in my C++ book and still it's not working out. Please help.

I would have an easier time doing this in Java.

Edit
Report

1 Answer

-2
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
        ifstream f("a.txt"); // check for errors.

        char ch,dummy;
        int i1,i2,i3,i4;

        f>>ch>>i1>>dummy>>i2>>i3>>dummy>>i4;

        cout<<ch<<endl<<i1<<endl<<i2<<endl<<i3<<endl<<i4<<endl;

        return 0;
}
answered 2010-02-02T03:01:35.397

Your Answer