Question-   Assign the size of userinput to stringsize. ex: if userinput is "hello ", output is:

Solution-

// write your answer here

Question: Assign the size of userInput to stringSize. Ex: if userInput is "Hello", output is:
Size of userInput: 5
#include <iostream>
#include <string>
using namespace std;

int main() {
string userInput;
int stringSize;

getline(cin, userInput);

/* Your solution goes here */

cout << "Size of userInput: " << stringSize << endl;

return 0;
}

Complete solution below:-

#include <iostream>
#include <string>
using namespace std;
 
int main() {
string Input;
int stringSizes,w,lent;
 
getline(cin, Input);
w=Input.length();
for(int i=0;i!=w;++i)
          {
          if (Input[i]!=' ')
          {
          lent++;
          }
          }
 
stringSizes=lent;
cout <<”\n”<< "Size of Input: " << stringSizes << endl;
 
return 0;

}

Our Happy Testimonials

They are fast in responding to homework questions. they have the best technical writers. Thanks for helping me with my programming doubts.

studentDyana
5  stars image

I contact to disklib for homework, they help me out, despite there was some technical issue they gone through extra mile for me and provide me good quality work in first priority. 100% recommended.

studying on laptopAsif Waheed
5  stars image

Desklib's study resources are best & unique. Their study database is easy to access and easy to use.
100 % recommended.

library and studentsMike Taylor
5  stars image