Getting this error code, is there something about std::remove() that I am not understanding here?

1>AoE2Wide.cpp(337): error C2664: 'strcpy' : cannot convert parameter 1 from 'std::string' to 'char *'

I tried using '=' instead of strcpy() too, no luck.

class Item
		int Pos;
		int ReferenceValue;
		std::string Type;
		int Parameter;
		std::string Comments;
		std::string Asm;
		int OriginalPos;
		Item(int p, int rf, std::string tp, std::string cm)
			Pos = p;
			ReferenceValue = rf;
			Type = tp;
			Comments = cm;
strcpy(item->Comments, std::remove(splitComment.at(1).begin(), splitComment.at(1).end(), ' ' ));
6 Years
Discussion Span
Last Post by MasterGberry

I think you're trying to cram too many commands into a single statement. The error will be easier to see if you simplify your statement(s).

The function strcpy() is a function from the C library, it is not a C++ function. It uses C-style strings, not newer C++ - Style std::string objects. If you want to use a std::string object as a data source for strcpy, you must use std::string::c_str() to extract the C-string equivalent from the std::string object.

Edited by Fbody: n/a


Fbody is right:

// I assume splitComment.at(1) is a std::list of std::string
string empty(" ");
std::remove(splitComment.at(1).begin(), splitComment.at(1).end(), empty);
std:list<std::string>::iterator iter;
for(iter = splitComment.at(1).begin(); iter != splitComment.at(1).end(); iter++)
    strcat(item->Comments, (*iter).c_str());

Edited by algoritmish: n/a


Comments is of type string and std::remove returns a ForwardIterator, so your logic is incorrect. I think you want something like so :

string::iterator newEnd= std::remove(splitComment.at(1).begin(), splitComment.at(1).end(), ' ' );
item->Comments = string(splitComment(1).begin(),newEnd);

I can't be certain without seeing more code.


Ty to all, I used FirstPerson's explanation. I have no idea what an iterator is though, I guess I have some reading to do, unless someone has a simple explanation, if its 5-10 pages of reading then I will read it, if its a 2 sec explanation I would appreciate it :)

This question has already been answered. 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.