Concantenation Help?
So, I'm trying to complete some beginner challenges. And I have hit a problem. Here it is..
both[i] = name[i] + " has eaten " + pancakes[i] + " pancakes";
|
That is all you need to know, but if you need more, tell me. How could I concatenate these?
That is not all I'd need to know.
That could very well be good syntax depending on what types the variables are.
name is a String. pancakes is an int. both is a string
Why don't you tell us what error you are getting and save us the trouble of having to figure it out ourselves?
i am getting....
C:\Users\Luke\Documents\C++\Forums_Practice\Pancakes.cpp||In function 'int main()':|
C:\Users\Luke\Documents\C++\Forums_Practice\Pancakes.cpp|13|error: no match for 'operator+' in 'std::operator+(const std::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](((const char*)" has eaten ")) + pancakes[i]'|
||=== Build finished: 1 errors, 0 warnings ===|
|
You need to convert your "int" to a string or c-string as there is no operator that takes type of int.
Topic archived. No new replies allowed.