command line arguments

Hi all,

I would like to take in arguments from the c++ project properties where you can type in your command arguments there.However the output tend to show only the first character of the word.
The parameters that i have placed in the command arguments is 34567 5 6.
The output for the code below only gives me 3 rather than 34567.

Appreciate if anyone out there could enlighten me.
Thanks!




#include <iostream>

using namespace std;


int main(int argc, char* argv[])
{
cout << *argv[0];

}


I've never used command-line arguments in C++, but my guess is that since you are only outputting the first character in *argv you're only going to get one character.

It's not an array of strings, so you'll have to use more than the first value.

Edit: I was wrong about the array.
Last edited on
Remove the dereference operator * and it will print the entire string, not just the first character.

Also, traditionally, the first argument will actually be the path to your program executable, so testing your program in this way will be confusing.
Topic archived. No new replies allowed.