Sorry, I didn't notice that you really want the input with the spaces. Here are the two pieces of code above corrected to accept the entire line.
Preferred using standard string:
Code:
#include<iostream>
#include<string>
int main()
{
std::string string_a;
std::cout<<"What is your string: ";
std::getline(std::cin, string_a);
std::cout<<" The length of \""<<string_a<<"\" is " << string_a.length()<<std::endl;
return 0;
}
And using c-style strings:
Code:
#include<iostream>
#include<cstring>
int main()
{
char string_a[100];
std::cout<<"What is your string: ";
std::cin.getline(string_a, 100);
std::cout<<" The length of \""<<string_a<<"\" is " << strlen (string_a)<<std::endl;
return 0;
}