You are viewing our Forum Archives. To view or take place in current topics click here.
Need Some C++ Help
Posted:

Need Some C++ HelpPosted:

Lusteh
  • Junior Member
Status: Offline
Joined: Nov 04, 201013Year Member
Posts: 64
Reputation Power: 2
Status: Offline
Joined: Nov 04, 201013Year Member
Posts: 64
Reputation Power: 2
Hey Guys, Usually I Can Understand Whats Going On With C++ But As Far As Examples Go, Im Stuck

I Have A Data File With Columns Of Data.

Example:

123 6721 Bob

And it goes on for a few.

I've got my program reading in each line one by one until the end of file.

Now I want to have the a string to contain the line to where I can search the string till a white space( A Tab "\t") shows up and It will add it to a column. It will continue until there is no more string.

If you can Help please shoot me a message!
#2. Posted:
CLK
  • Wise One
Status: Offline
Joined: Jun 12, 201013Year Member
Posts: 531
Reputation Power: 33
Status: Offline
Joined: Jun 12, 201013Year Member
Posts: 531
Reputation Power: 33
I'd probably just peek the next char after reading the line and check its value to see if it's equal to '\t', and if it is put it in the next column list or whatever it is you're doing with it.

   char* FilePath = "PathToFile";
   ifstream file(FilePath);
   if (file.is_open())
   {
      // Start reading our lines
      while (file.good())
      {
         string temp;
         getline(file, temp);
         char* next;
         file.read(next, 1);
         if (*next == '\t')
         {
            // stuff here
         }
         else
         {
            file.seekg(int(file.tellg()) - 1, SEEK_SET);
         }
         delete[] next;
      }
   }
   else
   {
      cout << "File not good" << endl;
   }


It'd look something like that. I'm fairly new to C++ though, so...
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.