Searching for Number in txt file

I am still bad at C++ , but I am trying to improve ,I saw that ppl were asking this thing alot of times ,but I could not find anywhere something that would help me . They just post code without any explanation soo
Thing that my program does :
1. Downloading txt file from Internet on D part. //done
2.Getting serialNumber of pc .//done
3. Checking is serialNumber is equal to some of numbers in txt file .
if you can atleast say to me what I can edit in this code for this to work properly .Thanks in advance ,and for If I wasted your time.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

int sum = serialNumber;
	int x;
	ifstream inFile;
	inFile.open("D:\\checker.txt");
	if (!inFile) {
		cout << "Unable to open file";
		exit(1); 
	}

	while (inFile >> x) {
		sum = sum + x;
	}

	inFile.close();
	cout << "Sum = " << sum << endl;
Last edited on
Are you searching for a specific number or just any number?
Try to think of ways to search for numbers.
I mean txt file has few lines of number for ex. 10
231515010
123410513
231412014
123410125
123141244
123141642
231312415
123141515
213154151
614123415
serialNumber have to be equal to one of those numbers else program will close.
Soo that means I am searching for serialNumber in file.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
bool foundTheNumber = false;
while (inFile >> x) 
{
  if (x == the_number_you_are_looking_for)
  {
    foundTheNumber = true;
    break;
  }
}

// Do something based on foundTheNumber 
Last edited on
Thanks you soo much can I somehow give you +1 or ? @Repeater
Topic archived. No new replies allowed.