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

std::for_each on a member function with 1 argument

I'm wondering how to implement what is stated in the title. I've tried something like... std::for_each( a.begin(), a.end(), std::mem_fun_ref( &myClass::someFunc ) ) but I get an error saying that the "term" (I"m assuming it means the 3rd argument)…
Person
  • 429
  • 1
  • 8
  • 16
3
votes
1 answer

how to get background color back to previous color after use of std handle

I'm using Visual Studio for C++ and we're writing our first code, however I've run into a 'simple' problem. In the code, I'm using each section as a function in itself, so for the output screen where it says "hit enter", it's calling a function to…
Becky Huard
  • 31
  • 1
  • 1
  • 2
3
votes
5 answers

Proper Way to size check a std::vector inside a loop

I have a std::vector that I need to loop through often. I see two ways of doing it First way: const size_t SIZE = myVec.size(); for (size_t i = 0; i < SIZE; i++) { myVec[i] = 0; } Second way: for (size_t i = 0; i < myVec.size(); i++) { …
The Vivandiere
  • 3,059
  • 3
  • 28
  • 50
3
votes
2 answers

C++ std::cin producing extra input

I am new to C++ and attempting to tackle some basic CodeJam problems. I am working on Reverse Words. I am running my code (in a unix environment) by piping in and out of the compiled executable: ./compiled.program < input_file.in >…
CorbinMc
  • 588
  • 2
  • 8
3
votes
0 answers

How to sort std::unordered_map by value in c++11 and get the most frequent elemts?

This question is similar to the: How to sort **boost::unordered_map** by value and return only keys in that order? But I want to know is there any new feature in c++11 that can solve the problem? This program solved my problem: #include…
user1436187
  • 3,252
  • 3
  • 26
  • 59
3
votes
1 answer

getting key_type from value_type

I have a class X that operates on std containers. A function that takes a value_type as argument must call a function that takes a key_type as argument. How do I do that? I seems so basic. template class X { void foo(typename…
XPlatformer
  • 1,148
  • 8
  • 18
3
votes
3 answers

initialization list of C++ containers of static const causes stack overflow

I have a static const variable of a std::vector as such: std::vector>> I've also tried(vectors in theory take less memory): std::unordered_map, HashGUID > std::map
mateuscb
  • 10,150
  • 3
  • 52
  • 76
3
votes
2 answers

Strange C++ compile error with valarrays

I have a strange compile error using valarrays in C++. This is a stripped down version of my code: #include #include using namespace std; bool test(const int &x,const valarray &a,const valarray &b) { return…
3
votes
1 answer

Is there a standard name / templated prototype for "congruent hash" vs "identity hash"?

I have a templated class Foo that can do identity comparisons (via ==), but has a function Foo::sameStructureAs(Foo const & other) for more of a "value" vs. "pointer" notion of equality. I'd like to make an unordered_map which overrides the hash…
3
votes
1 answer

std::endl results in crash

During the development of a simple example (I haven't programmed C++ for some time) I encountered a weird behaviour. Following hello world program crashes under Windows (Mingw): #include int main () { for (int idx = 0; idx < 5;…
nils
  • 1,362
  • 1
  • 8
  • 15
3
votes
1 answer

Rust standard library closure parameters: run time or compile time?

I was browsing the Rust standard library. It cought my eyes that when a closure is passed to a function as parameter, it is passed in run-time. For example from the Iterator trait: fn filter<'r>(self, predicate: 'r |&A| -> bool) -> Filter<'r, A,…
libeako
  • 2,324
  • 1
  • 16
  • 20
3
votes
1 answer

GCC stl_tree.h red-black tree source code for std::set

I am looking at the following GCC source code file stl_tree.h: https://gcc.gnu.org/onlinedocs/libstdc++/libstdc++-html-USERS-4.1/stl__tree_8h-source.html and in particular, this part: struct _Rb_tree_impl : public _Node_allocator { …
intrigued_66
  • 16,082
  • 51
  • 118
  • 189
3
votes
2 answers

Is there a simple / elegant way to push a Range of integers to an STD vector?

I have a simple task which is to initialize an std::vector with a range of integers. The range is given by the user, and i try to avoid using a for loop. Something like: void addRange(std::vector& vReturn, int nStart, int nEnd) { …
NirMH
  • 4,769
  • 3
  • 44
  • 69
3
votes
2 answers

std::map key no match for operator<

I'm having quite a hard time trying to debug my little piece of code: std::map myMap; glm::ivec3 myVec(3, 3, 3); myMap.find(myVec); I get the following error: c:\program files…
Benoît Dubreuil
  • 650
  • 1
  • 11
  • 27
3
votes
1 answer

How to handle stdout in node.js

I'm trying to automate a process I go through every time I test my apps and sites on the server. I'm currently running on nodejitsu. When I've tested something and it works on my local machine, the next thing I do is... Open my package.json…
Costa Michailidis
  • 7,691
  • 15
  • 72
  • 124