"Robert desouza" <ir******@yahoo.com> wrote in message
news:72**************************@posting.google.c om...
Hello Friends,
i am new to this group,i need some help regarding c++.i am having dat
file which contains 25450 random integers such as 16 7 20 243 37 297
3402 702 21405 304.............
my question is,how to read alternate integer for example
7,243,297,702..... from this dat file.anyones help will be
appreciated.
I'll assume the integers in your file are separated by
whitespace character(s). All you need do is read each
integer in succession, and 'throw away' the ones you
don't want. Example:
#include <cstdlib>
#include <iostream>
#include <fstream>
int main()
{
std::ifstream input("file.dat");
if(!input)
{
std::cerr << "Cannot open input file\n";
return EXIT_FAILURE;
}
int one(0);
int two(0);
while(input >> one >> two)
std::cout << two << '\n';
if(!input.eof())
std::cerr << "Error reading input file\n";
return 0;
}
Input file 'file.dat':
16 7 20 243 37 297
3402 702 21405 304
Output:
7
243
297
702
304
-Mike