Why does "auto" declare strings as const char* instead of std::string?

Viewed 12497

I made a template which adds the data it is given. If I use it like this, the compiler declares in_1 and in_2 as const char *, and the code doesn't compile.

#include <iostream>
using namespace std;
template <class T>
T addstuff(T part_1, T part_2){
    return(part_1+part_2);
}

int main(int argc, char const *argv[])
{
    auto in_1="Shut ";
    auto in_2="up.";
    cout<<addstuff(in_1, in_2)<<endl;
    return 0;
}

If I declare in_1 and in_2 std::string, it works like a charm.

Why can't (or doesn't) the compiler declare those strings automatically std::string?

4 Answers
Related