Funky
Funky

Reputation: 13608

return a string in C++

I have a function in my C++ where I would like to return a string. I have tried a few ways but get errors. I've tried the C# way of return "...."; return myString; But get errors every time.

EDIT:

Unhandled exception at 0x100c1486 (DGGGGG.dll) in TestConsoleApp2.exe: 0xC0000005: Access violation writing location 0x7a0dcc30.

Upvotes: 0

Views: 182

Answers (1)

dreamlax
dreamlax

Reputation: 95405

std::string methodReturningString()
{
    std::string something = "Hello ";
    something += "world!";
    return something;
}

Upvotes: 6

Related Questions