+ 2
Write a program to input the full name and then print total number of characters present in it, using c++. Make it short.
Input : Harsh Tirkey Output : 12 It should read space between the name as a character.
6 Antworten
+ 6
Yes, thats why I found it a little odd that you used it here. Thanks for clearing the doubt!
+ 5
#include<iostream>
#include<cstring>
using namespace std;
int main() {
char str[200];
cin.getline(str,200);
cout<<strlen(str);
return 0;
}
+ 4
@Atikrant Negi {Gamma}
I just had a doubt there. Why did you use a cin.get(ch) call before the getline()? Is it to clear the buffer so that getline() isn't skipped? Or is it something else?
+ 4
I wrote it by mistake .
cin.get(ch) is used before the getline() only in a loop if reading a value for first time . Cause I. that case it skips the first letter.
like here
.....//some code
cin.get(ch);
for(I=0;I<n;I++) {
cout<<"\n Enter your name";
cin.getline(name,100);
}
....//some code .
+ 3
@kinshuk
its for clearing the buffer zone .
If its not written there then the first letter of the input will be skipped .
+ 3
oh wait something is wrong .
That's not right .