I'm new to this community.
I got a program which get info from a .txt file then store it into a array for future use.However,when i try to get line from file with cities name,it didn't work that well.
Sameple for the line:
8175133 New York, New York, United States
7871900 Taipei, Taiwan
7785965 Kinshasa, Democratic Republic of the Congo
the point here is to get the weight(which are those long int) and the name of the cities(include the Country name .etc) then store them into a class named "Term" which has two variables "weight" and "query".Then store the "Term" class in a list.
My problem is,how can i do that?(get info from the file) The way i did it was to get whole line (such as "7871900 Taipei, Taiwan")then try to use "(getline(iss,get_line,' ')" but it didn't work and give me "0" for most of the lines.
Autocomplete Search_SL(10),Result_SL(k+1);
while (!in_file.eof())
{
string weight;
string query_LS;
long weight_LS;
string name;
getline(in_file,name);
istringstream iss(name);
for (int i = 0;i < 10;i++)
{
if (getline(iss,get_line,' '))
{
weight = get_line;
if (i == 1)
{
weight_LS = atoi(weight.c_str());
cout<< weight_LS<<endl;
}
else
{
query_LS += weight;
}
}
}
if (query_LS != "")
{
Term input_que(query_LS,weight_LS);
Search_SL.insert(input_que);
last++;
}
}
Let me know if you guys have any questions on my question! :P Thank you!
PS: Here's a sample output(correct one):
Please input the search query(type "exit" to quit):
Chic↵↵
1. 2695598 Chicago, Illinois, United States
2. 577375 Chiclayo, Peru
3. 86187 Chico, California, United States
I'm sure the rest of my program are right coz when i use other txt file which has line like "
1. 5627187200 the
2. 509184100 at
it will works