[TriLUG] Scripting & C++ question
oberry at trilug.org
Mon Nov 14 09:45:21 EST 2005
On Fri, Nov 11, 2005 at 04:43:02PM -0500, Mark Freeze wrote:
> On 11/11/05, Carolinux.com <bobevans19 at gmail.com> wrote:
> ls /dir/*.txt | yourCplusPlusProgram
> This didn't work for me...
> I thought it might be my program so I wrote the following simple
> program to test it.
> #include <iostream>
> #include <fstream>
> /* arg_test.cpp */
> using namespace std;
> int main(int argc, char *argv)
> for(int val=0; val<=argc; val++)
> cout << argv[val] << endl;
> return 0;
> This ("./arg_test bob carol ted alice") generates:
> However this (ls /home/mark/programs/cpp | ./arg_test) only generates:
> Any suggestions?
This wouldn't work because you are passing the file names into the
process on STDIN, but reading them as command line arguments.
You would need to use C functions getc(stdin) or gets(buff) or some
other variation, or std::cin >> buff, if you would like to use C++
More information about the TriLUG