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
5 answers

C++ - Call input function as a string

I'm new to c++ and I'm writing a program that executes certain commands. My program is supposed to have about 200 commands and using strcmp to check if the string is one among the command seems to be slow and inaccurate to me. I'm wondering if…
3
votes
2 answers

Does std::list's erase member function call the destructor for all stored elements?

I am debugging one memory issue it has some relation with the std::list::erase method. While reading the documentation for std::list::erase, I saw this statement: "This effectively reduces the container size by the number of elements removed,…
eswaat
  • 733
  • 1
  • 13
  • 31
3
votes
1 answer

What are the values of a std::vector initialized with a given size?

If i initialize a std::vector like this: vector sletmig(300); will it set all the 300 values to zero, or keep what was in my computer memory?
3
votes
1 answer

C++ LNK2019 unresolved external symbol stdlib

I have a program that requires atol() in one of its functions. So I included stdlib.h but it doesn't seem to see it. EDIT: I'm aware to use it, I should include stdlib.h. I did that but I'm still getting this error. The function: void intstr(…
3
votes
3 answers

std::cout for map

I have a map declared as follows map symbolTable; if(tempLine.substr(0,1) == "("){ symbolTable.insert(pair(tempLine, lineCount)); } How do I std::cout all of the things in my symbol table?
Barney Chambers
  • 2,720
  • 6
  • 42
  • 78
3
votes
5 answers

How efficient smart pointers are?

I know, that std::shared_ptr uses reference counting, so it has copy&move semantics, on the other hand std::unique_ptr (hence the name unique) only has move semantics, so trying to copy it is a compile error. However, its not quite clear for me how…
krispet krispet
  • 1,648
  • 1
  • 14
  • 25
3
votes
2 answers

How to track memory assign by STL library

I want to track all the memory(size allocated by std lib) allocated by all STL containers like map,list,vector etc. I just want to track STL container not regular object creation. Basically want to override new and delete of std lib. Example class…
eswaat
  • 733
  • 1
  • 13
  • 31
3
votes
1 answer

Check if std::move is done on container

Is there any way I can check is std::move done on some STL container? I have two types of classes (lets say A and B), they keep (some) instances of another class in their internal container. If instance of A keeps instance of B in it's container,…
mr.engineer
  • 187
  • 12
3
votes
2 answers

how do I access the vector value std :: vector pto

How do I access the vector value std :: vector pto into a separate vector x and y std :: vector x; already tried several ways: x (i) = pto.at (i) .pt.x but did not work
Marcos Basso
  • 31
  • 1
  • 2
3
votes
2 answers

Is it allowed to write to a ofstream when it is not opened in c++

I have a code like this: # in class definition std::ofstream m_myFile; ## some where in code m_myFile.open(filename); and then in several places, I am writing to file as follow: m_myFile << "some data to file"<
mans
  • 17,104
  • 45
  • 172
  • 321
3
votes
2 answers

Can different threads insert into a map if they always use different keys?

I'm trying to design a message queue for an object. There is a set of X threads that can all send message (to be processed later) to this object. If I have a std::map, is this thread safe, assuming thread one only adds messages…
Sam Kellett
  • 1,277
  • 12
  • 33
3
votes
2 answers

What's a good implementation of applying a unary function to some elements of a vector?

I'd like to apply a function UnaryFunction f to some elements of a std container, given a predicate UnaryPredicate p - sort of what you would get if you combine std::partition and then apply std::for_each to one of the partitions. I'm quite new to…
conciliator
  • 6,078
  • 6
  • 41
  • 66
3
votes
2 answers

std::regex_replace replace n occurences and get number of substitutions

I'm using std::regex_replace to modify the string. I need both to restrict substitutions made and to get number of them done. I used following code: std::wregex rx(pattern); size_t n = 0; // one match size_t ns = 3; wstring result = src; wstring…
Xanx
  • 545
  • 1
  • 5
  • 17
3
votes
2 answers

Wrong use of std::copy?

Here is a simple test program that illustrates the problem I faced: #include #include #include #include using namespace std; typedef unsigned char Byte; int main( ) { uint32_t ui32 = 12; size_t…
rightaway717
  • 2,631
  • 3
  • 29
  • 43
3
votes
1 answer

C++11 Using "Range-based for loop" (for each) for dynamic array

If I have a static array, I can do something like that: int a[] = {1, 2, 3}; for (const auto x: a) {printf("%d\n", x);} Can I do something similar when I have a pointer (int* b) and array size (N)? I'd rather avoid defining my own begin() and…
user972014
  • 3,296
  • 6
  • 49
  • 89