Question: I am new to C++, and haven't quite grasped all the concepts yet, so i am perplexed at why this function does not work. I am currently not at home, so i cannot post the compiler error just yet, i will do it as soon as i get home.

Here is the function.

```
const char * ConvertToChar(std::string input1, std::string input2) {
    // Create a string that you want converted
    std::stringstream ss;
    // Streams the two strings together
    ss << input1 << input2;
    // outputs it into a string
    std::string msg = ss.str();
    //Creating the character the string will go in; be sure it is large enough so you don't overflow the array
    cont char * cstr[80];
    //Copies the string into the char array. Thus allowing it to be used elsewhere.
    strcpy(cstr, msg.c_str());

    return * cstr;
}

```

It is made to concatenate and convert two strings together to return a const char \*. That is because the function i want to use it with requires a const char pointer to be passed through.

Answer: 
The code returns a pointer to a local (stack) variable. When the caller gets this pointer that local variable doesn't exist any more. This is often called dangling reference.

If you want to convert `std::string` to a c-style string use [`std::string::c_str()`](http://en.cppreference.com/w/cpp/string/basic_string/c_str).

So, to concatenate two strings and get a c-style string do:

```
std::string input1 = ...;
std::string input2 = ...;

// concatenate
std::string s = input1 + input2;

// get a c-style string
char const* cstr = s.c_str(); 
// cstr becomes invalid when s is changed or destroyed

```
Without knowing what the error is, it's hard to say, but this
line:

```
const char* cstr[80];

```

seems wrong: it creates an array of 80 pointers; when it
implicitly converts to a pointer, the type will be `char
const**`, which should give an error when it is passed as an
argument to `strcpy`, and the dereference in the return
statement is the same as if you wrote `cstr[0]`, and returns the
first pointer in the array—since the contents of the array
have never been initialized, this is undefined behavior. 

Before you go any further, you have to define what the function
should return—not only its type, but where the pointed to
memory will reside. There are three possible solutions to this:

Use a local static for the buffer:

This solution was
frequently used in early C, and is still present in a number of
functions in the C library. It has two major defects: 1)
successive calls will overwrite the results, so the client code
must make its own copy before calling the function again, and 2)
it isn't thread safe. (The second issue can be avoided by using
thread local storage.) In cases like yours, it also has the
problem that the buffer must be big enough for the data, which
probably requires dynamic allocation, which adds to the
complexity.

Return a pointer to dynamically allocated memory:

This works well in theory, but requires the client code to free
the memory. This must be rigorously documented, and is
extremely error prone.

Require the client code to provide the buffer:

This is probably the best solution in modern code, but it does
mean that you need extra parameters for the address and the
length of the buffer.

In addition to this: there's no need to use `std::ostringstream`
if all you're doing is concatenating; just add the two strings.
Whatever solution you use, verify that the results will fit.