Standard Libraries Flashcards

1
Q

How do you include the string library?

A

include

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you convert from a string to integer?

A

std::stoi(my_string);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you convert from a string to a double?

A

std::stod(my_string);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you convert from double/integer to string?

A

std::to_string(my_new_int);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is concatenating strings? How is it done?

A

This is combining strings.

std::string combined = string_1 + string_2 + string_3;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you obtain the first character from a string?

A

forename.front();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you obtain a specific character from a string?

A

forname[3];

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you insert a string into another string?

A

combined.insert(6, sub_string);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

how do you obtain a string from within another string?

A

combined.substr(0,3);

where 0 is the first letter and 3 is the 4th letter

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do you include the complex library?

A

include

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do you declare a complex variable?

A

std::complex c(2.0, -1.0);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do you extract the real part of a complex variable?

A

c.real()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How do you extract the imaginary part of a complex variable?

A

c.imag()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do you calculate the magnitude of the complex variable?

A

std::abs(c);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How do you calculate the phase angle of the complex variable?

A

std::arg(c);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How do you include vectors?

A

include

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

How do you declare a vector?

A

std::vector v;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

How do you calculate the number of elements of the vector?

A

v.size();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

How do you select an element in a vector?

A

v[2];

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

How do you add elements to a vector?

A

v.push_back(2);

21
Q

How do you remove the last element from a vector?

A

v.pop_back();

22
Q

How do you get the first element of a vector?

A

v.begin();

23
Q

How do you get the last element of a vector?

24
Q

How do you insert an element into a vector?

A

v. insert(v.begin(),6);

v. insert(v.begin() + 3,6);

25
How do you remove elements from a vector?
v.erase(v.begin(), v.begin() + 3);
26
How do you sort elements in a vector in ascending order?
std::sort(v.begin(), v.end());
27
How do you iterate through the elements of a vector?
for(std::vector::iterator i = v.begin(); i < v.end(); i++) { std::cout<< *i << std::endl; }
28
How do you sort elements in a vector in a descending order?
std::sort(v.begin(), v.end(), sort_descending);
29
What is a map?
This an array where each element is not tied to a specific number but instead tied to a string.
30
What is the string tied to an array position is referred to as:
Key
31
how do you include map?
#define
32
How do you create a map?
std::map int_map;
33
How do you add elements to a map?
int_map["Name"] = 39;
34
How do you erase elements from a map?
int_map.erase("Evans");
35
How do we select elements from a map?
To get the key we use: ->first | To get the value we use: ->second
36
How do you iterate through maps?
for(i = int_map.begin(); i != int_map.end(); i++) { std::string key = i-> first; int value = i->second; }
37
How do you obtain te values of a map without knowing its position?
int value = int_map["Name"];
38
How do you check to see if a key exists? What does it return?
int_map.count(key); | > Returns an integer number of times that that key is found
39
How do you include bitset?
#include
40
How do you declare a bitset?
std::bitset<8> my_empty_byte;
41
How do you declare and initialise a bitset with a value?
std::bitset<8> my_byte(128);
42
How do you declare and initialise a bitset with a hexadecimal?
std::bitset<8> my_byte(0x0F);
43
How do you declare and initialise a bitset with a binary value?
std::bitset<8> my_byte(std::string("00110011"));
44
How do you print bitsets?
std::cout << my_byte << std::endl;
45
How do you clear a bit toa 0?
my_byte.reset(7);
46
How do you set a bit to a 1?
my_byte.set(3);
47
How do you flip a bit>
my_byte.flip(3);
48
How do you access a single bit?
my_byte[5]; | my_byte.test(0);
49
What are the bit-wise operations?
``` AND = & OR = | XOR = ^ NOT = ~ Example: std::bitset<4> = z = a | b; ```