I know that it means this:


below is a string of 20 chars
[01234567890123456789]

The first twelve are
[012345678901]

The last twelve are
[890123456789]

the middle 4 of the first string are shown marked with () below:
[0123(4567)08901]

the middle for of the last twelve are shown marked with () below:
[8901(2345)6789]

Yes, I've read your jpeg.

But what code have you managed to come up with so far?


For example, can you read the string from the user, and just print it back to the user?
Can you add to that printing the length of the string?

I got till here,

#include <iostream>
#include <string>

using namespace std;

int main ()
{

string name;
cout<< "Enter name";
cin>> name;

Maybe this will kick-start you

#include <iostream>
#include <string>
using namespace std;
int main ( ) {
    string s = "hello world";
    cout << "The length is " << s.length() << endl;
    cout << "The 5th character is " << s[4] << endl;
    return 0;
}

There are all sorts of different methods for manipulating strings.
http://www.sgi.com/tech/stl/basic_string.html

There must be a cin

#include <iostream>
#include <string>
using namespace std;
int main ( ) {
string = name;
cin >> name;
cout << "The length is " << s.length() << endl;
cout << "The 5th character is " << s[4] << endl;


return 0;
}

to define a string variable,

string s;

then read in,

cin >> s;

then using the string stl use the necessary functions.

in particular look at, s.length(), s.substr()
the rest is trivial once you know how to use these functions.

This article has been dead for over six months. Start a new discussion instead.