Questions tagged [std]

The C++ Standard Library, and its namespace. Use in conjunction with [c++].

From Wikipedia

The C++ Standard Library provides several generic containers, functions to utilise and manipulate these containers, function objects, generic strings and streams (including interactive and file I/O).

http://en.wikipedia.org/wiki/C++_Standard_Library

The concept of using namespaces

http://en.wikipedia.org/wiki/Namespace_(computer_science)

Also see

4970 questions
89
votes
9 answers

Converting std::__cxx11::string to std::string

I use c++11, but also some libraries that are not configured for it, and need some type conversion. In particular I need a way to convert std::__cxx11::string to regular std::string, but googling I can't find a way to do this and putting (string) in…
jorgen
  • 3,425
  • 4
  • 31
  • 53
89
votes
5 answers

What would 'std:;' do in c++?

I was recently modifying some code, and found a pre-existing bug on one line within a function: std:;string x = y; This code still compiles and has been working as expected. The string definition works because this file is using namespace std;, so…
user1410910
  • 1,050
  • 6
  • 12
87
votes
3 answers

When is it necessary to use the flag -stdlib=libstdc++?

When is it necessary to use use the flag -stdlib=libstdc++ for the compiler and linker when compiling with gcc? Does the compiler automatically use libstdc++? I am using gcc4.8.2 on Ubuntu 13.10 and I would like to use the c++11 standard. I…
Raymond Valdes
  • 1,161
  • 1
  • 9
  • 15
86
votes
5 answers

How can I insert element into beginning of vector?

I need to insert values into the beginning of a std::vector and I need other values in this vector to be pushed to further positions for example: something added to beginning of a vector and values moved from position 1 to 2, from 2 to 3 etc. How…
Paweł Szymkowicz
  • 881
  • 1
  • 6
  • 3
85
votes
3 answers

do I need to close a std::fstream?

Possible Duplicate: Do I need to manually close a ifstream? Do I need to call fstream.close() or is fstream a proper RAII object that closes the stream on destruction? I have a local std::ofstream object inside a method. Can I assume that the…
Tobias Langner
  • 10,634
  • 6
  • 46
  • 76
84
votes
14 answers

Sorting std::map using value

I need to sort an std::map by value rather than by key. Is there an easy way to do it? I got one solution from the follwing thread: std::map sort by data? Is there a better solution? map testMap; // some code to generate the values…
user619237
  • 1,776
  • 3
  • 17
  • 19
83
votes
6 answers

Obtaining list of keys and values from unordered_map

What is the most efficient way of obtaining lists (as a vector) of the keys and values from an unordered_map? For concreteness, suppose the map in question is a unordered_map. I'd then like to obtain the keys as a vector, and…
Faheem Mitha
  • 6,096
  • 7
  • 48
  • 83
83
votes
4 answers

What would be a "Hello, World!" example for "std::ref"?

Can somebody give a simple example which demonstrates the functionality of std::ref? I mean an example in which some other constructs (like tuples, or data type templates) are used only if it is impossible to explain std::ref without them. I found…
Roman
  • 124,451
  • 167
  • 349
  • 456
83
votes
4 answers

Append an int to a std::string

Why is this code gives an Debug Assertion Fail? std::string query; int ClientID = 666; query = "select logged from login where id = "; query.append((char *)ClientID);
Hakon89
  • 1,011
  • 2
  • 9
  • 17
82
votes
5 answers

Why am I getting string does not name a type Error?

game.cpp #include #include #include #include "game.h" #include "board.h" #include "piece.h" using namespace std; game.h #ifndef GAME_H #define GAME_H #include class Game { private: string white; …
Steven
  • 1,061
  • 2
  • 10
  • 14
81
votes
7 answers

What is the fastest way to change a key of an element inside std::map

I understand the reasons why one can't just do this (rebalancing and stuff): iterator i = m.find(33); if (i != m.end()) i->first = 22; But so far the only way (I know about) to change the key is to remove the node from the tree alltogether and…
Peter Jankuliak
  • 3,464
  • 1
  • 29
  • 40
79
votes
26 answers

error C2065: 'cout' : undeclared identifier

I am working on the 'driver' part of my programing assignment and i keep getting this absurd error: error C2065: 'cout' : undeclared identifier I have even tried using the std::cout but I get another error that says: IntelliSense: namespace "std"…
Wallter
  • 4,275
  • 6
  • 29
  • 33
79
votes
4 answers

What's the difference between std::advance and std::next?

Is there more beyond advance takes negative numbers?
Tavison
  • 1,523
  • 1
  • 11
  • 19
78
votes
5 answers

std::lexical_cast - is there such a thing?

Does the C++ Standard Library define this function, or do I have to resort to Boost? I searched the web and couldn't find anything except Boost, but I thought I'd better ask here.
smallB
  • 16,662
  • 33
  • 107
  • 151
78
votes
2 answers

Why does unique_ptr take two template parameters when shared_ptr only takes one?

Both unique_ptr and shared_ptr accept a custom deleter to call on the object they own. But in the case of unique_ptr, the deleter is passed as a template parameter of the class, whereas the type of shared_ptr's custom deleter is to be specified as a…
qdii
  • 12,505
  • 10
  • 59
  • 116