how do i copy the 3 arrays into the fourth array

Excersice 4 says Write a program that contains four arrays. Three of the arrays should contain your
first name, middle initial, and last name. Use the string-copying function presented
in today’s lesson to copy these strings together into the fourth array, full name.


and this what i came up with
#include <iostream>
#include <string>
using namespace std;
using std::cout;
using std::endl;


int main()
{

char firstname[]="Franky";
char secondname[]="Padilla";
char middlename[]="Great";
char fullname[]={'\0'};

std::string strAddResult;

strAddResult=firstname + secondname + middlename;


fullname=strAddResult;

cout << "Full name\n" <<fullname <<endl;


return 0;



i get error message

--------------------Configuration: testtt - Win32 Debug--------------------
Compiling...
testtt.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\testing\testtt.cpp(18) : error C2110: cannot add two pointers
C:\Program Files\Microsoft Visual Studio\MyProjects\testing\testtt.cpp(21) : error C2440: '=' : cannot convert from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'char [1]'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Error executing cl.exe.

testtt.obj - 2 error(s), 0 warning(s)
Are you sure your teacher didn't mean strcat(), or strcpy()?

Anyway, the problem is that you can't add C strings. You need to first set the std::string to the first C string, and only then can you append the other strings with the += operator, but only one at a time.
Use the string-copying function presented
in today’s lesson

How could we know which function was presented in "today's lesson"?
I think you should use that one.
ihave no teacher, im teaching my self, today's lesson was on arrays, std::string and strcpy and strncpy











So use strcpy() ( http://www.cplusplus.com/reference/clibrary/cstring/strcpy.html )
but i think sprintf() would be easier... ( http://www.cplusplus.com/reference/clibrary/cstdio/sprintf.html )
even easier is casting firstname to a std::string and then using '+' :
strAddResult=(std::string)firstname + ' '+ secondname + ' ' + middlename;
Topic archived. No new replies allowed.