首页 > 其他 > 详细

#include <string>

时间:2016-07-09 10:28:11      阅读:151      评论:0      收藏:0      [点我收藏+]

 

c_str

string.c_str是Borland封装的String类中的一个函数,它返回当前字符串的首字符地址。

 

打印字符串,并执行

system(string1[i].c_str());

 

//std::array<std::string, 数组元素个数>

 

 1 #include <iostream>
 2 #include <array>
 3 #include <string>
 4 using namespace std;
 5 
 6 void main()
 7 {
 8     std::array<std::string, 5> string1 = { "calc","notpad","tasklist","mspaint","write" };//std::array<std::string, 数组元素个数>
 9 
10     for (int i = 0; i < 5; i++)
11     {
12         std::cout << string1[i] << std::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     std::string str1 = "task";
 9     std::string str2 = "list";
10     std::string str3 = str1 + str2;
11 
12     system(str3.c_str());
13 
14     system("pause");
15 }

 

#include <string>

原文:http://www.cnblogs.com/denggelin/p/5655189.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!