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!
|
Mentor
|
![]() |
| 16Jul2008,16:05 | #2 |
|
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?
|
|
Go4Expert Founder
|
![]() |
| 16Jul2008,19:56 | #3 |
|
Quote:
Originally Posted by xpi0t0s |
|
Go4Expert Member
|
|
| 22Jul2008,13:31 | #4 |
|
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;
}
Last edited by shabbir; 22Jul2008 at 13:47.. Reason: Code block |
|
Go4Expert Member
|
|
| 22Jul2008,13:33 | #5 |
|
don't forget
to writel #include<ifstream> using namespace std; |
|
Go4Expert Founder
|
![]() |
| 22Jul2008,13:48 | #6 |
|
Use code block
|


