////@Author PEZY//@Date Aug. 2014//@Brief// print the size and contents of the vectors from exercise 3.13.// Check whether your answers to that exercise were correct.// If not, restudy § 3.3.1 (p. 97) until you understand why you were wrong.//#include <iostream>#include <vector>#include <string>using std::vector;using std::string;using std::cout;using std::endl;int main(){vector<int> v1;cout << "{\n\"v1\":{\"size\":\"" << v1.size() << "\",\"value\":[";for (auto i : v1)cout << i << ",";if (!v1.empty()) cout << "\b";cout << "]}" << endl;vector<int> v2(10);cout << " \"v2\":{\"size\":\"" << v2.size() << "\",\"value\":[";for (auto i : v2)cout << i << ",";if (!v2.empty()) cout << "\b";cout << "]}" << endl;vector<int> v3(10, 42);cout << " \"v3\":{\"size\":\"" << v3.size() << "\",\"value\":[";for (auto i : v3)cout << i << ",";if (!v3.empty()) cout << "\b";cout << "]}" << endl;vector<int> v4{ 10 };cout << " \"v4\":{\"size\":\"" << v4.size() << "\",\"value\":[";for (auto i : v4)cout << i << ",";if (!v4.empty()) cout << "\b";cout << "]}" << endl;vector<int> v5{ 10, 42 };cout << " \"v5\":{\"size\":\"" << v5.size() << "\",\"value\":[";for (auto i : v5)cout << i << ",";if (!v5.empty()) cout << "\b";cout << "]}" << endl;vector<string> v6{ 10 };cout << " \"v6\":{\"size\":\"" << v6.size() << "\",\"value\":[";for (auto i : v6)if (i.empty()) cout << "(null)" << ",";else cout << i << ",";if (!v6.empty()) cout << "\b";cout << "]}" << endl;vector<string> v7{ 10, "hi" };cout << " \"v7\":{\"size\":\"" << v7.size() << "\",\"value\":[";for (auto i : v7)if (i.empty()) cout << "(null)" << ",";else cout << i << ",";if (!v7.empty()) cout << "\b";cout << "]}\n}" << endl;return 0;}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。