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
63
votes
7 answers

std::shared_ptr thread safety

I've read that "Multiple threads can simultaneously read and write different shared_ptr objects, even when the objects are copies that share ownership." (MSDN: Thread Safety in the Standard C++ Library) Does that mean that changing shared_ptr…
Roee Gavirel
  • 18,955
  • 12
  • 67
  • 94
62
votes
1 answer

What can and can't I specialize in the std namespace?

Users are allowed to add explicit specializations to the std namespace. However, there are a few templates that I am explicitly forbidden from specializing. What templates can and can't I specialize?
R. Martinho Fernandes
  • 228,013
  • 71
  • 433
  • 510
62
votes
2 answers

What is the use of "using namespace std"?

What is the use of using namespace std? I'd like to see explanation in Layman terms.
Jarvis
  • 629
  • 1
  • 6
  • 4
62
votes
5 answers

How is std::string implemented?

I am curious to know how std::string is implemented and how does it differ from c string?If the standard does not specify any implementation then any implementation with explanation would be great with how it satisfies the string requirement given…
yesraaj
  • 46,370
  • 69
  • 194
  • 251
62
votes
5 answers

string in namespace std does not name a type

This may just be a simple mistake that I'm not seeing, but I think I'm simply doing something wrong. Don't worry I'm not using namespace std in my header functions or anything which seemed to be this person's issue [Question I read similar to…
user1581100
62
votes
8 answers

How to iterate over a std::map full of strings in C++

I have the following issue related to iterating over an associative array of strings defined using std::map. -- snip -- class something { //... private: std::map table; //... } In the constructor I populate table…
crazybyte
  • 9,999
  • 5
  • 26
  • 22
60
votes
3 answers

What's the difference between cstdlib and stdlib.h?

When writing C++ code is there any difference between: #include and #include other than the former being mostly contained within the std:: namespace? Is there any reason other than coding standards and style to use one over…
Free Wildebeest
  • 7,272
  • 8
  • 38
  • 42
60
votes
5 answers

Does `sizeof` *really* evaluate to a `std::size_t`? Can it?

Take the following standard passage: [C++11: 5.3.3/6]: The result of sizeof and sizeof... is a constant of type std::size_t. [ Note: std::size_t is defined in the standard header (18.2). —end note ] Now: [C++11: 18.2/6]: The type size_t…
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
59
votes
6 answers

Why Can't I store references in a `std::map` in C++?

I understand that references are not pointers, but an alias to an object. However, I still don't understand what exactly this means to me as a programmer, i.e. what are references under the hood? I think the best way to understand this would be to…
ng5000
  • 12,330
  • 10
  • 51
  • 64
58
votes
6 answers

Fast way to write data from a std::vector to a text file

I currently write a set of doubles from a vector to a text file like this: std::ofstream fout; fout.open("vector.txt"); for (l = 0; l < vector.size(); l++) fout << std::setprecision(10) << vector.at(l) << std::endl; fout.close(); But this is…
Diego Fernando Pava
  • 899
  • 3
  • 11
  • 24
58
votes
2 answers

Transferring the ownership of object from one unique_ptr to another unique_ptr in C++11?

In C++11 we can transfer the ownership of an object to another unique_ptr using std::move(). After the ownership transfer, the smart pointer that ceded the ownership becomes null and get() returns nullptr. std::unique_ptr p1(new…
iampranabroy
  • 1,716
  • 1
  • 15
  • 11
58
votes
5 answers

Make custom type "tie-able" (compatible with std::tie)

Consider I have a custom type (which I can extend): struct Foo { int a; string b; }; How can I make an instance of this object assignable to a std::tie, i.e. std::tuple of references? Foo foo = ...; int a; string b; std::tie(a, b) =…
leemes
  • 44,967
  • 21
  • 135
  • 183
57
votes
9 answers

const unsigned char * to std::string

sqlite3_column_text returns a const unsigned char*, how do I convert this to a std::string? I've tried std::string(), but I get an error. Code: temp_doc.uuid = std::string(sqlite3_column_text(this->stmts.read_documents,…
LM.
  • 1,625
  • 3
  • 16
  • 23
57
votes
1 answer

Which std::sync::atomic::Ordering to use?

All the methods of std::sync::atomic::AtomicBool take a memory ordering (Relaxed, Release, Acquire, AcqRel, and SeqCst), which I have not used before. Under what circumstances should these values be used? The documentation uses confusing “load” and…
yonran
  • 18,156
  • 8
  • 72
  • 97
57
votes
5 answers

how to compare two std::set?

I do such comparison of two std::set #include #include using namespace std; #include #include int main(int argc, char** argv) { int myints1[]= {10,20,30,40,50}; int myints2[]= {50,40,30,20,10}; …
user2313793