Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   how to confirm presence of a number or word in a text file? (http://www.go4expert.com/forums/confirm-presence-word-text-file-t11700/)

Quarry 28Jun2008 11:24

how to confirm presence of a number or word in a text file?
 
Hi, I'm new to C++ (and to programming for that matter) I need help on how to check if certain words or numbers are present in a text file.

for example:

(is the number 255 in the text file?) True or False.

thanks!

xpi0t0s 16Jul2008 16:05

Re: how to confirm presence of a number or word in a text file?
 
It's not difficult, but we're not going to write the code for you. How far have you got and where are you stuck?

shabbir 16Jul2008 19:56

Re: how to confirm presence of a number or word in a text file?
 
Quote:

Originally Posted by xpi0t0s
It's not difficult, but we're not going to write the code for you. How far have you got and where are you stuck?

Exactly

aali 22Jul2008 13:31

Re: how to confirm presence of a number or word in a text file?
 
I think yoy should read the value from the file

Code:

int main () {
  string line;
  ifstream myfile ("example.txt");
  if (myfile.is_open())
  {
    while (! myfile.eof() )
    {
      getline (myfile,line);
      cout << line << endl;
    }
    myfile.close();
  }

if(line==value)
//value that you want to compare
  else cout << "Unable to open file";

  return 0;
}


aali 22Jul2008 13:33

Re: how to confirm presence of a number or word in a text file?
 
don't forget
to writel
#include<ifstream>
using namespace std;

shabbir 22Jul2008 13:48

Re: how to confirm presence of a number or word in a text file?
 
Use code block


All times are GMT +5.5. The time now is 15:20.