Hi, noob on board.

I have some issues with the spliting data according to tab.

What i need is to grab multiple inputs from a txt file and generate it into result txt file.

the input file reads like;

Johnny Bravo /tab S1234567
Systems /tab/tab DT012
VB /tab/tab DT234
Adv Database /tab DT978
.....


I can understand if all data are seperated by 1 tab, but some of the infos in the txt file, such as some subjects taking by Johnny are tabbed more than once in the txt file depend on the text length, probably because of the alignment.

Is there anyway for me to check for 1 or more tabs when getline()?

Thanks.

You can split the string into tokens using the stringstream class:

#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

int main() {
  string s;
  stringstream ss;
  vector<string> v;

  cout << "Please enter a string to be separated by tab characters:" << endl;
  getline( cin, s );

  // Convert the line of text into a list of tokens
  ss << s;
  while (getline( ss, s, '\t' )) v.push_back( s );

  cout << "The tokens are:\n";
  for (int i = 0; i < v.size(); i++)
    cout << i << ": " << v[ i ] << endl;

  return EXIT_SUCCESS;
  }

Try entering a string of words where you press the tab key here and there.

Hope this helps.

Hi, noob on board.

I have some issues with the spliting data according to tab.

What i need is to grab multiple inputs from a txt file and generate it into result txt file.

the input file reads like;

Johnny Bravo /tab S1234567
Systems /tab/tab DT012
VB /tab/tab DT234
Adv Database /tab DT978
.....


I can understand if all data are seperated by 1 tab, but some of the infos in the txt file, such as some subjects taking by Johnny are tabbed more than once in the txt file depend on the text length, probably because of the alignment.

Is there anyway for me to check for 1 or more tabs when getline()?

Thanks.

You know how to check for 1 TAB, right? So check the next character to see if it's a TAB too.

Thanks guys!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.