How can I concatenate const char and std::string?

Nov 22, 2016 at 3:25pm
outputBrowser->Text += *(std::string*)ApiClass::GetName(*(int*)(i)) + "\n";;
outputBrowser->Text += " ";
AnnounceChildren(*(int*)i);
prefix = prefix->Remove(prefix.Length - 5);

The first line shown gives me the error of "no operator ' + ' matches these operands". How can I put the two together?
Nov 22, 2016 at 4:49pm
Sounds like a common symptom of omitting #include <string>
Nov 22, 2016 at 7:29pm
I removed that inclusion and I have the same problem.
I am still looking to correct this error.
Nov 22, 2016 at 10:23pm
No, you need to #include <string> to use string operations in C++. If that doesn't help, you need to post minimal program that others can feed to a compiler and observe your error message.

Here's a minimal demo that compiles your first line of code:
1
2
3
4
5
6
7
8
9
10
11
#include <string>
int x = 1, *i = &x;
std::string s;
struct ApiClass {
    static std::string* GetName(int) { return &s; }
    std::string Text;
} b, *outputBrowser = &b;
int main()
{
    outputBrowser->Text += *(std::string*)ApiClass::GetName(*(int*)(i)) + "\n";;
}

demo: http://coliru.stacked-crooked.com/a/6bef9e15d3e50719

Last edited on Nov 22, 2016 at 10:24pm
Topic archived. No new replies allowed.