I am trying to combine the string NCards and Scards into one string called Tcards.
I am using # include <cstring> and I get an error. How would I fix this. All the variables are strings.

void deck::deal()
	Tcards=strcpy(Scards, Ncards);

6 Years
Discussion Span
Last Post by Lerner

strcpy(dest,source) copies the source to the destination
EDIT: strcpy returns the destination string, you're treating it like it returns a concatenated one.

What you need is to strcpy Scards into Tcards and then use strcat to add Ncards to Tcards. Make sure Tcards is big enough to take on both strings.

Edited by jonsca: n/a


Need more input. What is the declaration for the xCards? If they are Cstyle strings then you can't assign one to the other and if they are STL string objects then they won't work with strcpy().

For Cstyle strings there is a strcat() function that will concatenate one string onto the other, assuming the first string has enough space to accomate the second string. Then, once you have concatenated B onto A you can copy A into C with strcpy.

For STL string objects you can use the + operator to concatenate B onto A and then use the assingment operator to assign the new, modified and longer A to C.

Edit: Need to type faster.

Edited by Lerner: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.