較C語言而言是新式字符串:
#include<iostream>
#include<array>#include<string>
void main1()
{
double db[4] = { 1.1,2.2,3.3,4.4 };
std::array<double, 4>newdb = { 5.5,6.6,7.7,8.8 };
std::array<double, 4>newdb2 = newdb;//新型數組和老數組的區別在於可以直接用數組賦值
for (int i = 0; i < 4; i++)
{
std::cout << newdb[i] << " " << newdb2[i] << std::endl;
}
std::cin.get();
}
void main2()
{
std::array<std::string, 4> string1 = { "calc","tasklist","notepad","mspaint" };
for (int i = 0; i < 4; i++)
{
std::cout << string1[i] << std::endl;
system(string1[i].c_str());//c_str是爲了與c語言兼容,在C語言中沒有string類型,c_str吧string轉換成c中字符串樣式
}
std::cin.get();
}
void main()
{
std::string str1 = "task";
std::string str2 = "list";
std::string str3 = str1 + str2;
system(str3.c_str());
std::cin.get();
}