首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

C++char有关问题

2013-09-28 
C++char问题char *str 青年杂志(上半年)char str[] 青年杂志(上半年)如上两种,怎么才能把字符串

C++char问题

char *str = "青年杂志(上半年)";
                  char str[] = "青年杂志(上半年)";


如上两种,怎么才能把字符串中字符一个一个显示出来?

c++?char
[解决办法]

int main()
{
char *str = "青年杂志(上半年)";
char str1[] = "青年杂志(上半年)";
int nLen = strlen(str);
char Temp[4];

for (int i=0; i<nLen; i=i+2)
{
memcpy(Temp, str+i, 2);
Temp[2]='\0';

cout << Temp;
}
cout << endl;

for (int j=0; j<nLen; j=j+2)
{
memcpy(Temp, str1+j, 2);
Temp[2]='\0';

cout << Temp;
}

cout << endl;


cout << str << "," << str1 << endl;

return 0;
}


在VC6下,测试没问题。

热点排行