string pop_back function error - c++

I am having a problem with modifying a string. I appreciate your assistance; thank you!
struct Drawings::menues
{
std::vector<std::string> variable;
} Menue[numMenues];
Menue[1].variable.at(0).pop_back();
the above code gives me the following error
error: 'class std::basic_string<char>' has no member named 'pop_back'|
I am using codeblocks 12.11 and am using the gnu gcc compiler and the C++11 flag under compiler settings fixed my problem.
thank you all!

pop_back was introduced in C++11. Make sure your compiler supports it and compile with -std=c++11 (or -std=c++0x only if -std=c++11 is not supported on your version of the compiler).

Related

Error "is_enum not declared in this scope" when trying to compile my wxWidgets program

The G++ compiler shows the following errors when I try to compile:
C:\wx\include\wx\strvararg.h|350|error: 'is_enum' in namespace 'std' does not name a template type|
C:\wx\include\wx\strvararg.h|354|error: 'is_enum' was not declared in this scope|
C:\wx\include\wx\strvararg.h|354|error: template argument 1 is invalid|
I am using Code::Blocks for this, with a non-monolithic DLL build of wxWidgets.
Thanks for any help!
As Brian already indicated, you should enable C++11. There are two ways of doing this as you can see What are the differences between -std=c++11 and -std=gnu++11?.
As I remember, when compiling the whole wxWidgets library, I used -std=gnu++11 and had no problems.
Just to add to macroland comment:
You should consider upgrading to gcc version 5.2+. This version(s) does have a full set of c++11 features, whereas previous versions have them partially.

Brace-initialization of an array of structs in c++11

Here is my code:
#include <string>
struct A
{
int a;
std::string sa;
};
int main()
{
A arr[3]{};
}
When I compile it with gcc 4.8.2 (on Ubuntu 14.04) with -std=gnu++11 option I get the following error:
example.cpp: In function ‘int main()’:
example.cpp:11:14: internal compiler error: in gimplify_init_constructor, at gimplify.c:4271
A arr[3]{};
^
Why does it throw an internal compiler error? Is it a compiler bug?
An internal compiler error is always a compiler bug, and says nothing about whether the code is valid.
If the code is invalid, the compiler is supposed to give an error message telling you what's wrong with the code. An internal compiler error only tells you what's wrong with the compiler.
Given that this internal compiler error still exists in later versions (I just checked 4.9.2, as well as current sources as of January 29th), I would normally strongly encourage reporting this as a bug to the GCC developers, but a quick search reveals that it's already known to them.
You can work around it by writing A arr[3]{{}};, which means the same thing. It contains the same initialiser for the first element of arr that it would already get by default.
I encountered the same issue right out of blue with gcc 4.8.5 when I added an std::string to a content of the array struct. Adding extra {} as suggested above helped. Maybe this can give a clue why this compiler error happens.

No way to compile smart pointer with mingw-w64

I am using lasted mingw w64 compiler (from April 2014, with g++ 4.9.0), and I am unable to compile smart pointers (including <memory> header ), either with -std=c++0x or gnu0x. I get always same error:
error: 'shared_ptr' in namespace 'std' does not name a template type
I was told that lastest gcc was able to compile that. But this don't seem to be my case. I am missing anything?
Remove the -ansi compiler flag. For C++, it is equivalent to -std=c++98.
It comes after -std=c++11 and is overriding it. std::shared_ptr did not exist in C++98

array not a member of namespace::std

I am using g++ version 4.5.2 .
Although I have include array header file
#include <array> it does not complain about the existence of the header file.
But when I do std::array<char , 16>,
the exception is thrown when I try to compile with g++
"array not a member of namespace std"
I searched on the net and saw a suggestion somewhere to use std::tr1::array<>,
but that did not help either ?
Does someone know what the problem is ?
You need to compile with GCC 4.6 and later to have C++11 features and you need to set the right flag to -std=C++0x or in GCC 4.7 -std=C++11

bind is not a member of std

I am using netbeans 7.2.1 with minwg compiler. I am getting the following error messages when trying to build the application:
error: 'function' in namespace 'std' does not name a type
error: 'bind' is not a member of 'std'
although I included functional.h in the begining of the file, and I am using 'function' and 'bind' in the form of: std::function and std::bind
Where is the problem? Is it in the compiler or there is something missing? I remember that I compiled and ran the same application successfully on visual studio 2010.
It is not functional.h, it is just functional.
#include <functional> //without .h
Note that std::function and std::bind come with C++11 only. So you might have to upgrade your compiler in case you have not done yet.
Also, compile your code with -std=c++11 option:
$ g++ -std=c++11 file.cpp
That should work if you've upgraded your compiler. If your compiler is a bit old, you can also try -std=c++0x instead.
You need to include the header functional. It is available in C++11. If you are still having problems, then your compiler may not support C++11 yet. Try upgrading.
You can also use boost::bind:
#include <boost/bind.hpp>