char转换成string的问题 ,有点急!
我现在想循环建立26个文件,每个文件的名字叫做a.tmp,b.tmp,...,z.tmp。但是我是用char*p来指向a,b,c,z的。但是如何转换成string类型的,而且转换成功之后,我怎么把新的string加上 ".tmp "去构成一个文件名呢,这里面要调用string的 什么函数?请各位赐教 !
[解决办法]
string s = p; // char *p = 'a ';
s = s + ".tmp ";
string s(p);
[解决办法]
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
int main()
{
char *p= "a.tmp ";
char *p1= "b.tmp ";
string a(p);
string b(p1);
cout < <a < <endl;
cout < <b < <endl;
a.erase(1,4);
b.erase(1,4);
cout < <a < <endl;
cout < <b < <endl;
system( "PAUSE ");
return 0;
}
[解决办法]
CString strName;
char ch;
char chName[2];
chName[1] = '\0 ';
for (ch = 'a '; ch <= 'z '; ch++)
{
chName[0] = ch;
strName = chName;
strName += ".bmp ";
}