The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #7 (permalink)  
Old 05-20-2008
WebKruncher WebKruncher is offline
Registered User
 

Join Date: Dec 2007
Location: Simi Valley, CA
Posts: 28
args

argv is a double pointer to strings. Just dumping the pointer to stdout won't work out very well. Consider traversing the array, using argc to resolve the end of the list of pointers.

#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
using namespace std;

int main(int argc,char** argv)
{
vector<string> args;
for (int i=1;i<argc;i++)
{
args.push_back(argv[i]);
}

for (vector<string>::iterator it=args.begin();it!=args.end();it++)
{
string& s=*it;
cout<<s<<endl;
}
return 0;
}
Reply With Quote