+ 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.

24th Nov 2017, 12:08 PM
Harsh Tirkey
Harsh Tirkey - avatar
6 Antworten
+ 6
Yes, thats why I found it a little odd that you used it here. Thanks for clearing the doubt!
24th Nov 2017, 2:05 PM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 5
#include<iostream> #include<cstring> using namespace std; int main() { char str[200]; cin.getline(str,200); cout<<strlen(str); return 0; }
24th Nov 2017, 1:17 PM
RZK 022
RZK 022 - avatar
+ 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?
24th Nov 2017, 1:58 PM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 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 .
24th Nov 2017, 2:04 PM
RZK 022
RZK 022 - avatar
+ 3
@kinshuk its for clearing the buffer zone . If its not written there then the first letter of the input will be skipped .
24th Nov 2017, 2:00 PM
RZK 022
RZK 022 - avatar
+ 3
oh wait something is wrong . That's not right .
24th Nov 2017, 2:02 PM
RZK 022
RZK 022 - avatar