c++ - Convert a String to an int and store the result in a variable -
int units;
void input(int i) { char temp[50]; printf("enter class id #%d > ", + 1); readline(classid); printf("enter name #%d > ", + 1); readline(classname); printf("enter description #%d > ", + 1); readline(description); printf("enter pre-reqs #%d > ", + 1); readline(prereqs); printf("enter units > "); readline(temp); // write method convert string temp integer , store in units field
i think need nested loop not sure how go conversion please help.
use atoi()
function cstdlib
(you need include cstdlib
@ top of file):
units = atoi(temp);
it converts char array integer. see here.
you can use strtol()
allows error checking, see here details. credit: @nathanoliver
Comments
Post a Comment