A
arnuld
I have 2 programs.
1st PROGRAM: copies an input file to standard output but it
does so at the expense of deleting all white-space
(space, tabs, newlinies etc).
2nd PROGRAM: copies the input as it is to the standard output.
WHAT I WANT:
I want to merge the 2 programs, I want to do what 2nd program does
by replacing "while loop" with "std::copy" as in 1st program.
any idea ?
int main( int argc, char** argv )
{
std::vector<std::string> svec;
if( argc < 2 )
{
std::cerr << "No input file\n" << std::endl;
return EXIT_FAILURE;
}
else
{
std::ifstream infile( argv[1] );
std::copy( std::istream_iterator<std::string>( infile ),
std::istream_iterator<std::string>(),
std:stream_iterator<std::string>( std::cout, "\t" ));
}
return EXIT_SUCCESS;
}
---------------------------------------------------------
int main( int argc, char** argv )
{
std::vector<std::string> svec;
if( argc < 2 )
{
std::cerr << "No input file\n" << std::endl;
return EXIT_FAILURE;
}
else
{
std::ifstream infile( argv[1] );
std::string aline;
while( getline( infile, aline ))
{
std::cout << aline << std::endl;
}
}
return EXIT_SUCCESS;
}
1st PROGRAM: copies an input file to standard output but it
does so at the expense of deleting all white-space
(space, tabs, newlinies etc).
2nd PROGRAM: copies the input as it is to the standard output.
WHAT I WANT:
I want to merge the 2 programs, I want to do what 2nd program does
by replacing "while loop" with "std::copy" as in 1st program.
any idea ?
int main( int argc, char** argv )
{
std::vector<std::string> svec;
if( argc < 2 )
{
std::cerr << "No input file\n" << std::endl;
return EXIT_FAILURE;
}
else
{
std::ifstream infile( argv[1] );
std::copy( std::istream_iterator<std::string>( infile ),
std::istream_iterator<std::string>(),
std:stream_iterator<std::string>( std::cout, "\t" ));
}
return EXIT_SUCCESS;
}
---------------------------------------------------------
int main( int argc, char** argv )
{
std::vector<std::string> svec;
if( argc < 2 )
{
std::cerr << "No input file\n" << std::endl;
return EXIT_FAILURE;
}
else
{
std::ifstream infile( argv[1] );
std::string aline;
while( getline( infile, aline ))
{
std::cout << aline << std::endl;
}
}
return EXIT_SUCCESS;
}