Hi,

I need help with my homework please, its due tommorow and i prommise to show my efforts in the next days :sad:

http://www2.filehost.to/files/2006-10-16_03/214316_cplus.jpg

Thanks in advance :)

Recommended Answers

All 7 Replies

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.