item databasing in *.txt

hello. i'm having trouble with finding a specific number in text file.

my problem is:
create a text file that contain numbers in 3 lines. each lines consist of 5 numbers.
create a program that finds the first number in the first column
and load the rest of the 5 numbers in the program.

here's an example:

in text.txt
1001 27 12 17 33
1002 22 12 312 22
1003 873 1222 22 1

the program should read 1001 and then saves "1001, 27, 12, 17, 33" to variables inside the program.

any ideas? your reply is much appreciated.
Last edited on
what code you have currently?
i didn't really bring my copy of my code. i use internet cafe to access the web.
but my logic on the code was..
1
2
3
4
5
6
7
8
9
fstream unfile("text.txt");
if(infile.is_open())
{
infile>>first_number;
if(first_number==The_number)
{
infile>>second_number>>third_number...;
}
}


i'm not sure if what i remember now is the same on my code on my computer. but it doesn't work.
any ideas?
Last edited on
the contents of ITEM_DB.txt is:
1
2
3
4
5
101 knife 12 2 3
102 axe 8 22 1
103 8 23 1
...
..


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include<iostream>
using namespace std;
#include<fstream>

int main()
{
	int inInfile_id_no, inId_no;
	int inVar1, inVar2, inVar3;
	string names;
	
	
	while(1)
	{
		fstream file("ITEM_DB.txt");
		cout<<endl<<"enter the id no to be searched: ";
		cin>>inId_no;
		do
		{
			file>>inInfile_id_no>>names>>inVar1>>inVar2>>inVar3;
		}while(inId_no!=inInfile_id_no);
		cout<<endl<<inInfile_id_no<<" "<<names<<" "<<inVar1<<" "<<inVar2<<" "<<inVar3;
		file.close();	
	}
	
	return 0;
}
}
Last edited on
Topic archived. No new replies allowed.