Manipulating string length()

Hi guys, I need help writing a program that formats a paragraph from user-inputted words. The user should be allowed to input the desired width of the paragraph (10-70 characters) and have the option of having the paragraph boxed (optional) and centered (optional).
By creating a string variable that will contain the complete, formatted, paragraph. Using a loop to input words from the keyboard and append them to this string. Use the string length().

I'm having trouble manipulating length(), string::length.
I can't use simple input output like
1
2
3
char string::length;
cout << "Enter the desired width for your paragraph: " << endl;
cin >> string::length


Sample dialogue should look something like this:

Enter the desired width for your paragraph: 70
Do you want the paragraph boxed? yes
Do you want the box centered? yes
Enter paragraph ending with "endtext"
I hear there's rumors on the Internets that we're going to have a draft.
Rarely is the question asked: Is our children learning?
They misunderestimated me. endtext

Your paragraph follows:

+------------------------------------------------------------------------------+
|I hear there's rumors on the Internets that we're going to have a draft.      |
|Rarely is the question asked: Is our children learning?                       |
|They misunderestimated me.    					               |
+------------------------------------------------------------------------------+

Where the bold parts are user input and can be changed.

I've checked out reference and documentation but can't find anything that describes manipulating string::length through input.
If someone could just point me in the right direction...
I'm not sure why you want to "manipulate" string::length through input. When the string is modified via input, the length field will be updated automatically; you don't change it yourself.

Note that you can't use cin for reading text that includes whitespace; for that you need to use getline().
This is very easy. But i am not available printing the code right now.
Here what you must do:

Every character variable with any of these settings(width, centered, boxed...) should be declared with a ASCII picture. Like -------------------------------
ASCII PICTURE
------------------------------
Hey try out my algorithm:
Just change the name string to your input_line string and add cin.getline(...) instaed if cin>>string...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <string>
#define LINES 5

using namespace std;

int main(){
string str;
int width[LINES] = {1, 1, 1, 1, 1};
char* spacer[LINES] = {"11111", "11111", "11111", "11111", "11111"};
cout << "Enter your name: " << endl;
cin >> str;
for(int i = 0; i < 5; i++){
cout << width[i] << " <<<< ";
if(i == 4){
cout << endl;

for(int i = 0; i < LINES; i++){

if(i == 2){
cout << str << " |" << endl;
}
cout << spacer[i] <<" <<<< |" <<endl;
if(i == 4){


for(i = 0; i < LINES;i++){
cout << width[i] << " <<<< ";
}
}

}


}

}

cout << endl;
system("PAUSE");
return 0;
}
Topic archived. No new replies allowed.