因为要用到C++中将字符串与数字连接,竟然发现C++没有直接的字符串连接符,感觉C++的不便啊,找了些文章,解决了,主要得把数字先变成char数组 这种方法
测试代码如下:
#include <iostream>
using namespace std ;
#include<string>
int main ( )
{
string strDir ( ".\\test\\dazhong-allinone\\" ) ;
char file_no [ 4 ] ;
int filen = 123 ;
itoa ( filen , file_no , 10 ) ; //把数字存储为char的数组
strDir += file_no ; //string是标准库类型,可以直接与char的数组进行+号连接
strDir += ".txt" ;
cout << strDir << endl ;
system ( "pause" ) ;
return 0 ;
}
运行结果:
.\test\dazhong-allinone\123.txt
请按任意键继续. . .