How can I calculate string length which is separated with space in C++?

WI Wimtenbrink asked on 25 May 2020, 05:19
1 answers / 710 views / 4 votes
KA

Here is the code: (when input is taken from the user/keyboard)

string ar;
int m;
getline(cin,ar); // input an space separated string
m=ar.length(); // count total number of character of that string including space
cout << m << endl;

Sample input & output:

Input: {a, b,c ,d }
Output: 12
Input : Quora is the best site.
Output: 23

Related Questions

In

asked on 03 July 2020, 15:13
1 answers / 159 views / 5 votes