0

Hi I am new to C++ coding, and I was given a a task that requires me to add 2 simple numbers together through using parameters. I have checked my code with all my friends and it is fine, yet I am receiving the same error (There is an access violation in your program. Do you want to break it?) In the output box its stopping at ("[New Thread 3120.0x1724]\n")

I am using wxDev-C++ and my pc is a windows7 64bit

My code:

using namespace std;

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

{

  int a,b;


  a = atoi (argv[1]);
  b = atoi (argv[2]);

  cout << a+b<< endl;
  return 0;

}
Mark Hall
  • 53,938
  • 9
  • 94
  • 111
  • Get smarter friends? :) – David Grayson Mar 17 '12 at 01:44
  • 1
    Re: "Hi I am new to C++ coding" - [***Get an introductory C++ book and read it.***](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) It will cover basic things like this and much, much more. It's a lot less frustrating that way. – In silico Mar 17 '12 at 01:45
  • Are you sure you are passing two args in the cmd line? How are you invoking the program? – David Grayson Mar 17 '12 at 01:49
  • One thing you need to do is check the size of argv[] before assigning using it. argc is the number of index's that are available in argv[] in your case it should not be less than 3 – Mark Hall Mar 17 '12 at 02:08
  • Yes I am passing 2 args through – user1275188 Mar 17 '12 at 04:04

1 Answers1

0

The code is right.Maybe you don't use the comand line correctly.

XiaJun
  • 1,855
  • 4
  • 24
  • 41