store linux command in variable

Hello everyone

I'm trying to use linux command in C++ code to find out the number of lines in a file. Here's the line of code

 
system("wc -l < 00403.dat");


it works fine but is there any way I can store the result in a variable. E-g if it returns 1000 then I want to store it in an int type of variable.

Thanks
You can, but you'll have to use popen.
And if you just want to count lines, then the following approach is better on at least a dozen different levels:

1
2
3
4
ifstream is("00403.dat");
string dummy;
int lines=0;
while (getline(is,dummy))lines++;
Alright

Thanks Athar :-)
Topic archived. No new replies allowed.