変数
#include <sstream>
#include <iomanip>
#include <fstream>
void basicVariable() {
const int c = 10;
int r = 0;
int& r2 = r;
r2 = 100;
std::cout << r << std::endl;
Point p;
p.x = 10;
p.y = 10;
std::cout << p.d2() <<std::endl;
ColorType1 type1 = ColorType1::RED;
ColorType2 type2 = ColorType2::RED;
ColorType3 type3 = ColorType3::RED;
ColorType1 type4 = RED;
std::cout << type1 << std::endl;
std::cout << static_cast<int>(type2) << std::endl;
std::cout << static_cast<int>(type3) << std::endl;
std::cout << type4 << std::endl;
auto x = "x";
std::string z = "ac";
auto y = 3.0;
auto z1 = z + z;
auto z2 = x + z;
auto z3 = z + x;
std::string z5 = z.append(x);
std::string z6 = z.append(z);
z.empty();
std::cout << x << std::endl;
std::cout << y << std::endl;
std::cout << z << std::endl;
std::cout << z5 << std::endl;
std::cout << z6 << std::endl;
int sample = 100;
decltype(sample) sample2 = 200;
decltype(getValue()) sample3 = 3.3;
std::cout << sample << sample2 << sample3 << std::endl;
std::string stresc = "a\nb\nc";
std::string stresc2 = R"(a
b
c)";
std::cout << stresc << std::endl;
std::cout << stresc2 << std::endl;
int* a = nullptr;
if (a == nullptr) {
std::cout << "nullptr" << std::endl;
}
}
文字列
#include <iostream>
void stringUse() {
std::string x = "aaa";
std::string y = "bbb";
std::string z = x + y;
std::cout << z << std::endl;
}
ベクトル
#include <iostream>
#include <vector>
void vectorUse() {
std::vector<int> v = {1,5,10,100};
v[2] = 100;
v.push_back(50);
for (int x: v) {
std::cout << x << std::endl;
}
std::vector<int> v2 = {1,3,2,5};
v2.insert(v2.end(), v.begin(), v.end());
std::cout << "v2" << std::endl;
for (int x: v2) {
std::cout << x << std::endl;
}
}