I have two question:
1. how to read the string below into token ?
2. how to include the query into the token without having to reprint it?
I have made a thread earlier but i have fixed and this version is shorter so i hope one of you will help me.. Thanks

#include <iostream>
#include <fstream>
#include <map>
#include <string>
#include <cstdlib>
using namespace std;
int main() {
    map<string, string> Data; // map of words and their frequencies
    string key;           // input buffer for words.
	fstream File;
	string description;
	string query;
	int count=0;
	int i=0;

	File.open("J://Customers.txt");

    while (!File.eof())
	{
		getline(File,key,'\t');
		getline(File,description,'\n');
        Data[key] = description;
    }
	File.close();

cout << endl;

 for ( count=0; count < 3; count++)
 {
	cout << "Type in your search query. ";
	cin >> query;
	cout << query << "	"<< Data[query] << endl;
		string token[11];   
		istringstream iss(Data[query]);  
		while ( getline(iss, token[i], '\t') )   
		{     
			cout << token[i] << endl;
                                                i++;
		}
 }
	system("pause");

}//end main

TEXT FILE

CustomerID	CompanyName	ContactName	ContactTitle	Address	City	Region	PostalCode	Country	Phone	Fax
ALFKI	Alfreds Futterkiste	Maria Anders	Sales Representative	Obere Str. 57	Berlin		12209	Germany	030-0074321	030-0076545
ANATR	Ana Trujillo Emparedados y helados	Ana Trujillo	Owner	Avda. de la Constitución 2222	México D.F.		05021	Mexico	(5) 555-4729	(5) 555-3745
ANTON	Antonio Moreno Taquería	Antonio Moreno	Owner	Mataderos  2312	México D.F.		05023	Mexico	(5) 555-3932

Remove the declaration of the variable int i=0; from line 14 and place it in between 33-34 or 34-35.

The problem is that the scope of the variable which retains the value of 11 after the first for loop and therefore causing the program to crash.,

The other thing you can do is to just place i=0 at line 34-35.

Hi thanks for the useful reply,

You forgot to #include <sstream>

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.