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
78
votes
2 answers

'vector' in namespace 'std' does not name a type

I am developing a C++ application using CodeBlocks 10.05 on Debian 7.0.0. For some reason, the following code #include std::vector< int > delaunayDiv(const std::vector< int > & vP, cv::Rect boundRect, std::vector& triangles,…
OtagoHarbour
  • 3,969
  • 6
  • 43
  • 81
77
votes
3 answers

Why has std::reduce been added in C++17?

I was looking for a thorough explanation of the meaning of "Return value" description for std::reduce, which according to cppreference.com, is: Maybe after I properly understand this section, I can better determine when I should choose std::reduce…
Aria Pahlavan
  • 1,338
  • 2
  • 11
  • 22
75
votes
7 answers

How to convert std::chrono::time_point to calendar datetime string with fractional seconds?

How to convert std::chrono::time_point to calendar datetime string with fractional seconds? For example: "10-10-2012 12:38:40.123456"
boxx
  • 1,111
  • 2
  • 9
  • 15
74
votes
2 answers

std vector C++ -- deep or shallow copy

I wonder whether copying a vector I am copying the vector with its values (whereas this is not working with array, and deep copy need a loop or memcpy). Could you hint to an explanation? Regards
kiriloff
  • 25,609
  • 37
  • 148
  • 229
71
votes
5 answers

Why does std::map not have a const accessor?

The declaration for the [] operator on a std::map is this: T& operator[] ( const key_type& x ); Is there a reason it isn't this? T& operator[] ( const key_type& x ); const T& operator[] const ( const key_type& x ); Because that would be incredibly…
Calder
  • 2,219
  • 1
  • 20
  • 21
70
votes
3 answers

How to create an std::function from a move-capturing lambda expression?

I'm trying to create an std::function from a move-capturing lambda expression. Note that I can create a move-capturing lambda expression without problems; it's only when I try to wrap it in an std::function that I get an error. For example: auto pi…
seertaak
  • 1,087
  • 1
  • 9
  • 17
69
votes
2 answers

std::put_time implementation status in GCC?

I was trying to compile this example program using GCC (tested versions 4.5.1, 4.6.3, 4.8.4): #include #include #include #include using std::chrono::system_clock; int main() { system_clock::time_point now…
moooeeeep
  • 31,622
  • 22
  • 98
  • 187
68
votes
6 answers

Does std::vector.clear() do delete (free memory) on each element?

Consider this code: #include void Example() { std::vector list; TCHAR* pLine = new TCHAR[20]; list.push_back(pLine); list.clear(); // is delete called here? // is delete pLine; necessary? } Does list.clear()…
Ignas Limanauskas
  • 2,436
  • 7
  • 28
  • 32
68
votes
1 answer

How can I use Standard Library (STL) classes in my dll interface or ABI?

There have been a few questions before on exporting a class which contains stl classes in relation to visual studio warning C4251: E.g. this question or this question. I have already read the excellent explanation at UnknownRoad. Blindly disabling…
André
  • 18,348
  • 6
  • 60
  • 74
68
votes
5 answers

std::string vs string in c++

Possible Duplicates: Why is 'using namespace std;' considered a bad practice in C++? Using std Namespace I've been hovering around a bunch of different forums and I seem to see this pop up every time and again. It's a very much beginner…
OVERTONE
  • 11,797
  • 20
  • 71
  • 87
68
votes
8 answers

Is list::size() really O(n)?

Recently, I noticed some people mentioning that std::list::size() has a linear complexity. According to some sources, this is in fact implementation dependent as the standard doesn't say what the complexity has to be. The comment in this blog entry…
foraidt
  • 5,519
  • 5
  • 52
  • 80
68
votes
8 answers

C++ create string of text and variables

I'm trying to do something very simple and yet, after an hour of so of searching a I can't find a suitable answer so I must be missing something fairly obvious. I'm trying to dynamically create filenames for use with ifstream. Whilst I understand…
Jack Farrow
  • 737
  • 1
  • 7
  • 6
67
votes
4 answers

Ambiguous overload call to abs(double)

I have the following C++ code: #include #include // per http://www.cplusplus.com/reference/clibrary/cmath/abs/ // snip ... if ( (loan_balance < 0) && (abs(loan_balance) > loan_payment) ) { ... } and make blows up…
some_man
65
votes
4 answers

Is there a tab equivalent of std::endl within the standard library?

Using C++, is there an equivalent standard library constant for '\t' like there is for a newline? Ideally: std::stringstream ss; ss << std::tab << "text"; If not, why is this the case? (I'm aware I can just insert a '\t' but I'd like to sate my…
matthewrdev
  • 11,930
  • 5
  • 52
  • 64
63
votes
8 answers

Is it good practice to use std::vector as a simple buffer?

I have an application that is performing some processing on some images. Given that I know the width/height/format etc. (I do), and thinking just about defining a buffer to store the pixel data: Then, rather than using new and delete [] on an…
Roger Rowland
  • 25,885
  • 11
  • 72
  • 113