istream& getline (istream& is, string& str)
, usage:
#include<iostream>
int main(){
std::string output;
std::getline(std::cin, output);
}
One line, taken from std::cin
, is stored in output
. You can read each output
's char using output[i]
, where i
is number of char you want get, or use output.data()
, which returns same data, stored in char[]
.
Each of this methods lets you to read char
as a character. It seems you want to get a digit as a number, not as character.
char
is also number. Each letter has it's own code.
char code
'0'==48
'1'==49
'2'==50
'3'==51
'4'==52
'5'==53
'6'==54
'7'==55
'8'==56
'9'==57
As you can see, digits are beautiful set one after another, and digit more about n
has code more about also n
. How to use it? Simple: just take char
after char
, each reduced by 48
or '0'
for better readability, to get digits as numbers.