C++Primer Fifth Edition: Exercise 3.12 3.13 3.14 3.15

Exercise 3.12

int main()
{
    
    
	vector<vector<int>> ivec;
	vector<string> svec = ivec;
	vector<string> svec(10, "null");
}

(B) Error, type does not match

Exercise 3.13

int main()
{
    
    
	vector<int> vec;//0元素
	vector<int> v2(10);//10元素 元素为0
	vector<int> v3(10, 42);//10元素 元素为42
	vector<int> v4(10);//10元素 元素为0
	vector<int> v5(10, 42);//10元素 元素为42
	vector<string> v6(10);//10元素 元素为空string对象
	vector<string> v7(10, "hi");//10元素 元素为"hi"
}

Exercise 3.14

int main()
{
    
    
	vector<int> vec;
	int n;

	while (cin >> n)
		vec.push_back(n);
}

Exercise 3.15

int main()
{
    
    
	vector<string> vec;
	string n;

	while (cin >> n)
		vec.push_back(n);
}

Guess you like

Origin blog.csdn.net/Xgggcalled/article/details/109047090