Questions tagged [c++-standard-library]

In the C++ programming language, the C++ Standard Library is a collection of classes and functions, which may or may not be written in the core language, and are part of C++

The C++ Standard Library is a collection of classes and functions, which are nearly all written in the core language and part of the C++.

The C++ Standard library should not be confused with C++ standard template library. The was thee inspiration for a big subset of C++ Standard Library, specifically containers, algorithms, iterators, and function-objects.

Online-reference:

Books

848 questions
868
votes
26 answers

How to convert an instance of std::string to lower case

I want to convert a std::string to lowercase. I am aware of the function tolower(). However, in the past I have had issues with this function and it is hardly ideal anyway as using it with a std::string would require iterating over each…
Konrad
  • 35,953
  • 29
  • 74
  • 111
508
votes
40 answers

std::string formatting like sprintf

I have to format std::string with sprintf and send it into file stream. How can I do this?
Max Frai
  • 52,556
  • 73
  • 182
  • 293
471
votes
7 answers

What's the difference between "STL" and "C++ Standard Library"?

Someone brought this article to my attention that claims (I'm paraphrasing) the STL term is misused to refer to the entire C++ Standard Library instead of the parts that were taken from SGI STL. (...) it refers to the "STL", despite the fact that…
Pieter
  • 28,337
  • 74
  • 160
  • 235
169
votes
9 answers

C++ valarray vs. vector

I like vectors a lot. They're nifty and fast. But I know this thing called a valarray exists. Why would I use a valarray instead of a vector? I know valarrays have some syntactic sugar, but other than that, when are they useful?
rlbond
  • 59,991
  • 50
  • 166
  • 218
166
votes
8 answers

Deleting elements from std::set while iterating

I need to go through a set and remove elements that meet a predefined criteria. This is the test code I wrote: #include #include void printElement(int value) { std::cout << value << " "; } int main() { int initNum[] = {…
pedromanoel
  • 2,972
  • 2
  • 22
  • 23
129
votes
3 answers

Writing your own STL Container

Are there guidelines on how one should write new container which will behave like any STL container?
Avinash
  • 11,749
  • 27
  • 102
  • 175
110
votes
2 answers

What are the mechanics of short string optimization in libc++?

This answer gives a nice high-level overview of short string optimization (SSO). However, I would like to know in more detail how it works in practice, specifically in the libc++ implementation: How short does the string have to be in order to…
ValarDohaeris
  • 5,269
  • 5
  • 25
  • 41
103
votes
11 answers

What does string::npos mean in this code?

What does the phrase std::string::npos mean in the following snippet of code? found = str.find(str2); if (found != std::string::npos) std::cout << "first 'needle' found at: " << int(found) << std::endl;
boom
  • 5,194
  • 21
  • 52
  • 88
99
votes
2 answers

How to get the file size in bytes with C++17

Are there pitfalls for specific operating systems, I should know of? There are many duplicates (1, 2, 3, 4, 5) of this question but they were answered decades ago. The very high voted answers in many of these questions are wrong today. Methods…
Jonas Stein
  • 5,932
  • 5
  • 35
  • 67
93
votes
1 answer

Why is libc++'s vector::const_reference not bool?

Section 23.3.7 Class vector [vector.bool], paragraph 1 states: template class vector { public: // types: typedef bool const_reference; ... However this program fails to compile when…
Howard Hinnant
  • 179,402
  • 46
  • 391
  • 527
89
votes
4 answers

Are the experimental features of modern C++ reliable for long-term projects?

I have a project that currently uses C++11/14, but it requires something like std::filesystem, which is only available in C++17, and hence I don't have a chance to currently use it. I see, however, that it's available in my current compiler as…
The Quantum Physicist
  • 21,050
  • 13
  • 77
  • 143
87
votes
9 answers

Why is there no transform_if in the C++ standard library?

A use case emerged when wanting to do a contitional copy (1. doable with copy_if) but from a container of values to a container of pointers to those values (2. doable with transform). With the available tools I can't do it in less than two steps :…
Nikos Athanasiou
  • 24,831
  • 11
  • 72
  • 136
82
votes
10 answers

std::queue iteration

I need to iterate over std::queue. www.cplusplus.com says: By default, if no container class is specified for a particular queue class, the standard container class template deque is used. So can I somehow get to the queue's underlying deque and…
jackhab
  • 15,012
  • 32
  • 92
  • 129
77
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
  • 14,808
  • 29
  • 97
  • 144
74
votes
5 answers

C++ Filehandling: Difference between ios::app and ios::ate?

What's the difference between ios::ate and ios:app when writing to a file. In my view, ios::app gives you the ability to move around in the file, whereas with ios::ate it can only read/write at the end of the file. Is this correct?
Adam_G
  • 6,417
  • 17
  • 69
  • 120
1
2 3
56 57