C++ Assignment storing strings

Hi, sorry to bother everyone but I am new at C++ and Have no idea how to do this.

2. Write a program that stores a string containing a full name (First Middle Last) with a single space between any two successive names then it outputs each part of the name in a separate line. For testing purpose, your program MUST use the following name “Henry Louis Aaron” where the output in this case will as given below. Make sure that your program should function properly in case you use any other full name (it should be generic).

First Name: Henry
Middle Name: Louis
Last Name: Aaron
Hint: You need to use various string manipulation functions.


any help is appreciated!
A good start is declaring three string variables and you could call them first, middle, and last.

1
2
3
#include <string>

string first, middle, last;

Can anyone give me more help. I'm still stumped.
bump
1
2
3
4
 
string first, middle, last;
cout << "Enter you full name: ";
cin >> first >> middle >> last;


or

1
2
3
string name;
cout << "Enter you full name: ";
getline (cin, name);
Last edited on
how do i substitute his name in for first, middle and last for the strings to get the output?? im still a little confused..
Is that the whole question? it says you need to use various string manipulation functions yet I just don't see the need for any...

ok they say we must use the name given so perhaps they mean concatenation:
1
2
3
4
5
6
7
8
9
string first="Henry";
string middle="Louis";
string last="Aaron";

string name;

name = first + " " + middle + " " + last;

cout << "Name is: " << name << endl;
Last edited on
lol
Last edited on
plzzz help me im so confused.... and theres alot of errors in my code can anyone help?? this is what i got so far.

#include <string>

string first, middle, last;
cout << "Enter you full name: ";
cin >> first >> middle >> last;

string first="Henry";
string middle="Louis";
string last="Aaron";

string name;

name = first + " " + middle + " " + last;

cout << "Name is: " << name << endl;
You are trying to declare the same string variables...get rid of "string" before you assign the names to the variables.
which string?? can you be more specific please like im really a noob at this so idk what your talking about.
I wrote a very simple code but it gets the job done
even if the person has a longer name
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
#include <stdio.h>

int main()
{
    int i = 0, m, l;    
    char strNames[50];
    gets(strNames);
    
    
    printf("First Name: ");
    for( ; strNames[i] != 32; i++ )
         printf("%c", strNames[i]);
    m = i;
    for( ; strNames[i] != '\0'; i++ );
    for( ; strNames[i] != 32; i-- );
    l = i;
    printf("\nMiddle Name:");
    for( ; m <= l; m++ )
         printf("%c", strNames[m]);
    printf("\nLast Name:");     
    for( ; strNames[l] != '\0'; l++ )
         printf("%c", strNames[l]);
getchar();
return 0;
}
try this

edit:Cshark beat me too it... even though his is in C and I can't understand it XD
Last edited on
I need this in C++ language!!!
Last edited on
give me 10 minutes and ill have it done

edit:sorry i don't have time. If i can ill do it in the morning
Last edited on
can anyone else translate this C into C++?? please!
Topic archived. No new replies allowed.