0
How can I input a word instead of just a letter?
7 Answers
+ 2
U can use string
+ 1
Set return type to array like char[] and return a char array that is a word
+ 1
Use getline method as:
Cin.getline(n,sizeof(n));
0
for example i set char n [50]. what do I put on cin? so that if I run the program I can input "name". because I tried cin>>n [i] in a for loop. then when I run it the program crashes when I input "name" but it runs when I input just a letter
0
#include <iostream>
#include <string>
using namespace std;
main() {
int i=0;
char n[50];
for(i=1; i<=2; i++){
cin>>n[i];
}
for(i=1; i<=2; i++){
cout<<n[i];
}
return 0;
}
0
I used this program then I input 'name and year' respectively for two inputs then the ouput is just "na"
0
how can I get.. when I input 'name' then output 'name' not just 'na'