Find numbers in a text file.

Hi, I want to filter out numbers from text rows in a textfile. But can't find a way to do it. Do you guys have an idea? Right now I have a code that just printing out the text lines in my file and how many lines there is as you can see.


1
2
3
4
5
6
7
8
9
10
11
12
13
  ifstream inputfile(filename);
  char text;
  int n = 0; 
  
  while (inputfile.get(text))
    {
      cout.put(text);
      if (text == '\n')
	++n;
    }
  
  cout << endl << There is " << n << " rows of text";
 
Hi!

I wrote a code but it has a handicap: if a word start number and continues letters then It will recognize a number. i.e. 123asda it is a number: 123
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <fstream>

using namespace std;


int main()
{
	ifstream inputfile;
	inputfile.open("probe.txt");
	if (inputfile.good())
	{
	int number = 0;
	inputfile >> number;
	if (!inputfile.fail()) cout << "succeeded";
	else cout << "didn't  succeeded";
	inputfile.close();
	}
	return 0;
}

Topic archived. No new replies allowed.