String Functions

Hi! This is my first string function encercise ever so I'm teaching myself this. Here is the excercise

Write a program that asks for a user first name and last name separately.
The program must then store the users full name inside a single string and out put it to the string.
i.e.
Input:
John
Smith
Output:
John Smith

I'm trying to make a construct a string object and store two seperate strings within that and output them as one. I'm having difficulties lol! I'd appreciate anyone's help! Thanks and Happy new years!

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
// Strings are your friends.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <string>

using namespace std;


int _tmain(int argc, _TCHAR* argv[])
{
	string first_name, last_name;

	cout << "Please enter your first name.\n";
	cin >> first_name;
	cout << "Please enter your last name.\n";
	cin >> last_name;

	string(first_name, last_name);
	
	cout << string(first_name, last_name);

	return 0;
}
here the example
you will know how to do and understand about it
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 <iostream>
#include <string>

using namespace std;

int main(){

	//Initialize are vvery important
	string firstname = "";
	string lastname = "";

	cout << "Enter First Name : ";
	cin  >> firstname;

	cout << "Enter Last Name : ";
	cin  >> lastname;

	//String object that store another two string object
	string Name = firstname + lastname;

	cout << "The Name is : " << Name << endl;

	system( "pause" );
	return 0;
}
Thanks for the response. It still fails it says...
code given by
@Felicia123
is correct, where you are getting error give full information about error.
If space is not coming between two strings use following statement.

string Name = firstname + " " +lastname;

The task given to you is to learn about string concatenation.
This is the error:

1>LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt
Change the project settings as below

Project Properties 
   -> Configuration Properties 
       -> Linker (General) 
          -> Enable Incremental Linking -> "No (/INCREMENTAL:NO)"


or if it not work

install VS2010 SP1.
Thanks a lot it worked!
Topic archived. No new replies allowed.