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
1 answer

Pass in subvector of vector into a function

So let's say I have an std::vector myVector; and a function myFunction(std::vector parameter); I want to be able to pass a subvector of myVector to myFunction without having to copy the elements over into a new vector first. Can this…
user1855952
  • 1,515
  • 5
  • 26
  • 55
3
votes
2 answers

Using std::queue with shared_ptr?

Consider the following bit of code: #include #include std::shared_ptr oneSharedPtr(new char[100]); std::queue> stringQueue; stringQueue.queue(oneSharedPtr); This results in error C2274: 'function-style…
UberMongoose
  • 319
  • 3
  • 9
3
votes
3 answers

When accessing std::map with static string values, is access time still O(log n)?

std::map dict; for(int i = 0; i < 300; ++i) { dict["afsfgsdg"] = i*i; dict["5t3rfb"] = i; dict["fddss"] = i-1; dict["u4ffd"] = i/3; dict["vgfd3"] = i%3; } Since the string values are already known at compile time,…
jokoon
  • 6,207
  • 11
  • 48
  • 85
3
votes
3 answers

c++ for each vector of strings

typedef std::vector TVector; TVector a_list; populate vector... for_each(a_list.begin(),a_list.end(),std::toupper); error no matching function for call to 'for_each(std::vector >::iterator,…
gda2004
  • 718
  • 13
  • 32
3
votes
2 answers

Why use namespace if iostream is imported

I am beginner at C++, and I have recently been introduced to namespaces like std. However, if functions like cout and endl are defined in the iostream header file, why include the std namespace at all? Or are these functions actually defined in the…
Bbvarghe
  • 267
  • 2
  • 5
  • 18
3
votes
1 answer

Usage Issue of std::align

Consider the following code: #include #include #include using namespace std; // Visual Studio 2012 don't have alignof as a keyword. #define alignof(type) __alignof(type) #define TEST_TYPE int int main(int,…
Jens Åkerblom
  • 898
  • 8
  • 19
3
votes
1 answer

Sequential sequence containers OR How to pack vectors

Imagine I have two vectors: std::vector A,B; //Push a bunch of data into A //Push a bunch of data into B For whatever reason, I want to create an interface to these vectors such as follows: packed combined(A,B); for(packed::iterator…
Richard
  • 56,349
  • 34
  • 180
  • 251
3
votes
7 answers

Infinite loop on EOF in C++

This code works as desired for the most part, which is to prompt the user for a single character, perform the associated action, prompt the user to press return, and repeat. However, when I enter ^D (EOF) at the prompt, an infinite loop occurs. I…
titaniumdecoy
  • 18,900
  • 17
  • 96
  • 133
3
votes
3 answers

Sorting a std::vector which has parts of it sorted (formed by concatenation of sorted vectors)

I have an std::vector as one of the inputs for an API i am exposing. I know that the user of this API can send a huge vector, but that vector was formed by concatenation of sorted vectors. This means that the vector that I get is formed from a…
AMM
  • 17,130
  • 24
  • 65
  • 77
3
votes
2 answers

Find index of value in Vector, nearest to the input

Is there an efficient method of finding the index of a value in a Vector, closest to a reference value?
eigen_enthused
  • 525
  • 6
  • 17
3
votes
1 answer

Validity of pointers after moving a std::set

I have a structure which conceptually has the following class C {/* expensive class */}; struct mapping { std::map, C> the_map; }; This is less than ideal as a large number of copies of C end up being stored. My current solution…
Peter Ogden
  • 710
  • 5
  • 10
3
votes
3 answers

Counting matches in vector of structs

I have a problem that requires me to count the number of instances within this array that uses either std::count() or std::find(). I'm aware of how to do this using a standard data (see bottom code) type but not with the NameContainer that I'm…
user2211776
  • 239
  • 1
  • 2
  • 11
3
votes
1 answer

Which std container behaviour is this?

I am trying to "hack" a game (Red Alert 3, closed source..) which is compiled using Visual Studio 2005 (MSVCR80.dll's needed to play), I try to make a program which shows the unit list of my opponents. As for that I first need to find a (static)…
user1182183
3
votes
2 answers

Removing and deleting all objects in a vector

Suppose I have an ivar vector myVector;. I add items to this vector. Later, I want to "reset" the vector to nothing and add items to again fresh. Can anyone confirm that the following are true: myVector.clear(); //removes objects but does not…
johnbakers
  • 24,158
  • 24
  • 130
  • 258
3
votes
1 answer

Searchable Ring Buffer

I was wondering if someone could suggest a c++ data structure that has both the capabilities of a Ring Buffer (guaranteed finite storage) but at the same time would allow the efficient thread-safe searching of the Ring Buffer for a specified data?
user1676605
  • 1,337
  • 3
  • 13
  • 21