Standard Libraries Flashcards
How do you include the string library?
include
How do you convert from a string to integer?
std::stoi(my_string);
How do you convert from a string to a double?
std::stod(my_string);
How do you convert from double/integer to string?
std::to_string(my_new_int);
What is concatenating strings? How is it done?
This is combining strings.
std::string combined = string_1 + string_2 + string_3;
How do you obtain the first character from a string?
forename.front();
How do you obtain a specific character from a string?
forname[3];
How do you insert a string into another string?
combined.insert(6, sub_string);
how do you obtain a string from within another string?
combined.substr(0,3);
where 0 is the first letter and 3 is the 4th letter
How do you include the complex library?
include
How do you declare a complex variable?
std::complex c(2.0, -1.0);
How do you extract the real part of a complex variable?
c.real()
How do you extract the imaginary part of a complex variable?
c.imag()
How do you calculate the magnitude of the complex variable?
std::abs(c);
How do you calculate the phase angle of the complex variable?
std::arg(c);
How do you include vectors?
include
How do you declare a vector?
std::vector v;
How do you calculate the number of elements of the vector?
v.size();
How do you select an element in a vector?
v[2];