Using atoi to get inputs?

Hello! I'm really new to using atoi and I've only really used it as shown below:

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

using namespace std;

int main(int argc, char** argv){

	float r = atoi(argv[1]);
	float i = atoi(argv[2]);

	cout << "The first input is " << r << " and the second is " << i << endl;

}


I compile it and then run it with: ./"test" 2 5
and that would output "The first input is 2 and the second is 5"


If I wanted to have a string display, saying something like "Please enter the first number: " and THEN have the user input a number, how would I go about doing that using atoi?

I've read: http://www.cplusplus.com/reference/cstdlib/atoi/
I'm trying to stay away from using printf since we aren't allowed to use it in my programming methodology class.
Do you mean like :
Please enter the first number : 5 <ENTER>
Five
?
Last edited on
Yup, just like that
Topic archived. No new replies allowed.