read string from a text file

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
Does it have to be C++?
Yes, it is c++.
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.
Hello kbw,

i want to give arguments and files with argc and *argv[] to the program. I do:

program.o 10 test1.inp test2.inp

and then i need that it work like this:

 
system ("abaqus cpus=argc job=test1");


But how will this work?

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.
Topic archived. No new replies allowed.