How to I read in a text file ignoring the digits, just want the text in the text file

Any sample code?

Recommended Answers

All 2 Replies

open the file, then read it one char at a time.
Then use isdigit on every char:

string str ="";
if (!isdigit(input_char))
{
   str+=input_char;  
}

When the loop is done, 'str' will contain your file without numbers.

Or you could read one line at a time (or even the whole file) and use standard algorithms to remove digits:

#include <algorithm>   // remove_if()
#include <cctype>      // isdigit()
#include <functional>  // ptr_fun<>
#include <string>

...

string remove_digits( const string& s )
  {
  string result( s );

  result.erase(
    remove_if(
      result.begin(),
      result.end(),
      ptr_fun<int,int>( isdigit )
      ),
      result.end()
    );

  return result;
  }

Enjoy.

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.