Set the variable via terminal -need help

Hi, I just started programming in linux today and I have problem with this simple source code. can you please help me, how can I change this code to do this on output after I enter ./hello BYE to terminal (hello has to be the default value):

BYE 0
BYE 1
BYE 2
BYE 3
BYE 4
BYE 5

#include <iostream>

using namespace std;

int main()
{
for(int i = 0; i < 10; i++)
{
cout << "Hello" << i << endl;
}
}

thank you for your help.
http://www.site.uottawa.ca/~lucia/courses/2131-05/labs/Lab3/CommandLineArguments.html

Which boils down to:


1
2
3
4
5
6
7
8
9
10
11
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
  for(int i = 0; i < 10; i++)
  {
     cout << argv[1] << i << endl;
  }
}


Last edited on
Topic archived. No new replies allowed.