"Max" <ma*@mxserve.com> wrote in message
news:pe********************@comcast.com...
Yea this is probably a n00b question, but I haven't programmed C++ in at
least 2 years and have never programmed for unix, sorry :)
C++ is topical here, operating systems are not.
C++ is a platform independent language, so it
doesn't matter which OS you use.
Anyway, I have a project in which a program is required to read from an
input file, process it and spit some stuff back out. The program will be
called from UNIX using "a.out < primary.input".
That primary.input file
has a number of lines that I need to read. How do I go about reading
them into a string type?
See below.
Is this anything related to the way command
line arguments work in windows, or completely different?
No, it has nothing to do with command line arguments, regardless
of the OS you use.
#include <algorithm>
#include <iostream>
#include <iterator>
#include <string>
#include <vector>
int main()
{
std::string line;
std::vector<std::string> data;
while(std::getline(std::cin, line))
data.push_back(line);
if(!std::cin.eof())
std::cerr << "error reading input\n";
std::cout << "file contents:\n";
std::copy(data.begin(), data.end(),
std::ostream_iterator<std::string>(std::cout, "\n"));
return 0;
}