which function is needed ?

Hello,

i have the code :

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
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <conio.h>
#include <algorithm>

using namespace std;

int main (void)
{
        char inpt[256]; 
	string surname ;   // i want to receive only the surname
        string name;       // the name is correct
        cout << "Enter your surname and name: "

	gets(inpt);     //use the example "Lucky Luke".
	
	surname = inpt;      // i want the surname.
        name    = inpt + 6 ; //  name is correct

	cout << name << "\n";
	cout << surname << "\n";

        cout << "\n\n" ;
        system("PAUSE"); //sorry for using that
        return 0;
}


Which function do i need in order to keep or save only the surname ? (which in this case is Lucky)

Any idea please?

Thank you very much .
It is not good for you
gets(inpt); //use the example "Lucky Luke".
istringstream in(inpt);
in >> surname;
@edit

Thank you very much.

i changed to getline.
Last edited on
That's exactly what aiby's code is doing.
Never use gets. Use getline instead.
Topic archived. No new replies allowed.