Question

#include <iostream>
#include <string>
using namespace std;

string buff, resultstr, userstr;

string convert(const string& userstr)
{
    buff = userstr.front();
    resultstr = userstr;
    resultstr.front() = '_';
    resultstr = resultstr + buff + "ay";
    return resultstr;
}

That's my code, I'm using QT Creator 3.1.0 with GCC 4.9.0 as a compiler, this gives me:

in function 'std::string convert(const string& userstr)':
'const string' has no member named 'front'
'std::string' has no member named 'front'

I googled around and found in an older question here that this would occur if your compiler doesn't support C++11, but GCC should have supported that since 4.8. am I doing something wrong? I'm brand new to C++ so I wouldn't be surprised.

Note: I skipped the "main" function because it's only being used to load the QT GUI.

Was it helpful?

Solution

To make gcc and other compilers work in C++11 mode you should add CONFIG += c++11 to your .pro file. Then std::string will have a member .front. It is better than adding -std=c++11 to QMAKE_CXXFLAGS because it will work with any compiler supported by Qt (Visual Studio, Sun Studio, etc). The downside to this that you will need a Qt 5 or higher version ofqmake. qmake will then read the required flag from your compiler mkspec (QMAKE_CXXFLAGS_CXX11) and append it to QMAKE_CXXFLAGS.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top