标签:
array是数据类型,double是数组元素类型,4是数组元素个数
array<double, 4> dbnew1 = { 10.1,10.2,10.3,10.4 };
新版数组可以实现整体操作
rray<double, 4> dbnew2 = dbnew1;
1 #include <iostream> 2 #include <array> 3 using namespace std; 4 5 void main() 6 { 7 double db[4] = { 1.1,2.2,3.3,4.4 }; 8 9 //array是数据类型,double是数组元素类型,4是数组元素个数 10 array<double, 4> dbnew1 = { 10.1,10.2,10.3,10.4 }; 11 array<double, 4> dbnew2 = dbnew1;//新版数组可以实现整体操作 12 13 for (int i = 0; i < 4; i++) 14 { 15 cout << db[i] << " "; 16 } 17 18 cout << endl; 19 20 for (int i = 0; i < 4; i++) 21 { 22 cout << dbnew1[i] << " "; 23 } 24 25 cout << endl; 26 27 for (int i = 0; i < 4; i++) 28 { 29 cout << dbnew2[i] << " "; 30 } 31 32 system("pause"); 33 }
打印字符串,并执行
使用c_str函数
system(string1[i].c_str());
1 #include <iostream> 2 #include <array> 3 #include <string> 4 using namespace std; 5 6 void main() 7 { 8 array<string, 5> string1 = { "calc","notpad","tasklist","mspaint","write" }; 9 10 for (int i = 0; i < 5; i++) 11 { 12 cout << string1[i] << endl; 13 system(string1[i].c_str()); 14 } 15 16 system("pause"); 17 }
字符串相加,类似C的strcat函数
1 #include <iostream> 2 #include <array> 3 #include <string> 4 using namespace std; 5 6 void main() 7 { 8 string str1 = "task"; 9 string str2 = "list"; 10 string str3 = str1 + str2; 11 12 system(str3.c_str()); 13 14 system("pause"); 15 }
标签:
原文地址:http://www.cnblogs.com/denggelin/p/5615276.html