Hello,
i have a text file like this:
123 abc **dddd
**ERROR hallo
**ERROR 1234567
This is from a calculation. I want to read out the Errors and i did this programming:
[cpp]
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string.h>
#include <fstream>
using namespace std ;
int main()
{
ifstream fileInput;
string line;
char* search = "ERROR";
for(unsigned int curLine = 0; getline(fileInput, line); curLine++) {
if (line.find(search) != string::npos) {
cout << "found: " << search << "line: " << curLine << endl;
}
}
}
[/cpp]
The compiling was sucssessfully but it found nothing. Can anyone help me?
Regards
Last edited on
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
#include <iostream>
#include <string.h>
#include <fstream>
using namespace std ;
int main()
{
ifstream fileInput("filename.txt");
string line;
const char search[] = "ERROR";
for(unsigned int curLine = 0; getline(fileInput, line); curLine++)
{
if (line.find(search) != string::npos)
{
cout << "found: " << search << "line: " << curLine << endl;
}
}
}
|
Last edited on
Thank you. It worked how i need it. When i have some other questions i will write to you.
Kind regards.
I missed this, you really should start another thread for a different question.
I don't quite understand the question. Can you explain what you mean please.