help using int main(int argc, char* argv[])

Using the code,

1
2
3
int main(int argc, char* argv[])
{
   cout << 3*argv[] << endl;


and calling it from command line as
./name_of_program 5

I want it to produce 15, but it wont let me.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <sstream>
#include <iostream>

int to_int(const char* s)
{
    std::istringstream is(s) ;

    int value ;
    is >> value ;
    return value ;
}

int main(int argc, const char* argv[])
{
    if ( argc == 2 )
        std::cout << 3*to_int(argv[1]) << '\n' ;
    else
        std::cout << "No argument provided.\n" ;
}
Topic archived. No new replies allowed.