Questions tagged [standard-library]

The standard library contains core utilities provided by all implementations of the language.

The standard library contains core utilities provided by all implementations of the language.

The size and scope of the standard library varies between languages, some provide only a few basic components for such things as string handling and I/O, whereas others provide higher-level tools for a wide variety of tasks such as XML processing, networking and database access.

For questions about specific languages' standard libraries use this tag in conjunction with the tag for the language, or use the indicated tags for these languages:

659 questions
633
votes
9 answers

Read whole ASCII file into C++ std::string

I need to read a whole file into memory and place it in a C++ std::string. If I were to read it into a char[], the answer would be very simple: std::ifstream t; int length; t.open("file.txt"); // open input file t.seekg(0, std::ios::end); //…
Escualo
  • 36,702
  • 18
  • 79
  • 122
500
votes
12 answers

How to check if a file exists in Go?

Go's standard library does not have a function solely intended to check if a file exists or not (like Python's os.path.exists). What is the idiomatic way to do it?
Sridhar Ratnakumar
  • 68,948
  • 61
  • 139
  • 172
406
votes
9 answers

What is std::promise?

I'm fairly familiar with C++11's std::thread, std::async and std::future components (e.g. see this answer), which are straight-forward. However, I cannot quite grasp what std::promise is, what it does and in which situations it is best used. The…
Kerrek SB
  • 428,875
  • 83
  • 813
  • 1,025
285
votes
44 answers

Removing duplicate elements from an array in Swift

I might have an array that looks like the following: [1, 4, 2, 2, 6, 24, 15, 2, 60, 15, 6] Or, really, any sequence of like-typed portions of data. What I want to do is ensure that there is only one of each identical element. For example, the above…
Altair357
  • 2,861
  • 2
  • 9
  • 4
209
votes
2 answers

What is std::decay and when it should be used?

What are the reasons for the existence of std::decay? In what situations is std::decay useful?
125
votes
11 answers

Why isn't `int pow(int base, int exponent)` in the standard C++ libraries?

I feel like I must just be unable to find it. Is there any reason that the C++ pow function does not implement the "power" function for anything except floats and doubles? I know the implementation is trivial, I just feel like I'm doing work that…
Dan O
  • 4,000
  • 5
  • 26
  • 43
110
votes
6 answers

Why is it OK to return a 'vector' from a function?

Please consider this code. I have seen this type of code several times. words is a local vector. How is it possible to return it from a function? Can we guarantee it will not die? std::vector read_file(const std::string& path) { …
Pranit Kothari
  • 8,997
  • 10
  • 55
  • 128
100
votes
14 answers

"Unresolved inclusion" error with Eclipse CDT for C standard library headers

I set up CDT for eclipse and wrote a simple hello world C program: #include int main(void){ puts("Hello, world."); return 0; } The program builds and runs correctly, but eclipse keeps showing this yellow question mark by the side…
Derrick Zhang
  • 19,341
  • 17
  • 48
  • 71
97
votes
27 answers

Getting a machine's external IP address with Python

Looking for a better way to get a machines current external IP #... Below works, but would rather not rely on an outside site to gather the information ... I am restricted to using standard Python 2.5.1 libraries bundled with Mac OS X 10.5.x import…
cit
  • 1,925
  • 4
  • 25
  • 36
92
votes
13 answers

Which functions from the standard library must (should) be avoided?

I've read on Stack Overflow that some C functions are "obsolete" or "should be avoided". Can you please give me some examples of this kind of function and the reason why? What alternatives to those functions exist? Can we use them safely - any good…
Andrei Ciobanu
  • 11,585
  • 20
  • 75
  • 115
85
votes
4 answers

Is there a standard java exception class that means "The object was not found"?

Consider a function of the following general form: Foo findFoo(Collection foos, otherarguments) throws ObjectNotFoundException { for(Foo foo : foos){ if(/* foo meets some condition*/){ return foo; } } …
abl
  • 5,554
  • 2
  • 21
  • 41
84
votes
4 answers

Concatenating strings doesn't work as expected

I know it is a common issue, but looking for references and other material I don't find a clear answer to this question. Consider the following code: #include // ... // in a method std::string a = "Hello "; std::string b =…
Andry
  • 14,281
  • 23
  • 124
  • 216
80
votes
11 answers

Case Insensitive String comp in C

I have two postcodes char* that I want to compare, ignoring case. Is there a function to do this? Or do I have to loop through each use the tolower function and then do the comparison? Any idea how this function will react with numbers in the…
bond425
  • 917
  • 1
  • 6
  • 12
78
votes
7 answers

Is there a module for balanced binary tree in Python's standard library?

Is there a module for an AVL tree or a red–black tree or some other type of a balanced binary tree in the standard library of Python?
aeter
  • 9,522
  • 4
  • 22
  • 28
74
votes
4 answers

Difference between C standard library and C POSIX library

I'm a little confused by "C standard lib" and "C POSIX lib", because I found that, many header files defined in "C POSIX lib" are also part of "C standard lib". So, I assume that, "C standard lib" is a lib defined by ANSI C organization, and there…
Alcott
  • 15,679
  • 24
  • 106
  • 170
1
2 3
43 44