How to concatenate a const char array and a char array pointer?

后端 未结 3 1252
梦谈多话
梦谈多话 2021-01-27 04:38

Straight into business: I have code looking roughly like this:

char* assemble(int param)
{
    char* result = \"Foo\" << doSomething(param) << \"bar\         


        
3条回答
  •  自闭症患者
    2021-01-27 05:13

    "Foo" and "Bar" are literals, they don't have the insertion (<<) operator.

    you instead need to use std::string if you want to do basic concatenation:

    std::string assemble(int param)
    {
        std::string s = "Foo";
        s += doSomething(param); //assumes doSomething returns char* or std::string
        s += "bar";
        return s;
    }
    

提交回复
热议问题