很多人说C++过时了,请问还有必要学习它吗?
另请帮我翻译,谢谢。
#include <iostream>
#include <string.h>
int main()
{
using namespace std;
char fname[]="H";
char sname[]="X";
char tname[]="M";
char flname[80]="";
int offset=0;
strcpy(flname,fname);
offset=strlen(fname);
strcpy(flname+offset," ");
offset+=1;
strcpy(flname+offset,sname);
offset+=strlen(sname);
strcpy(flname+offset," ");
offset+=1;
strcpy(flname+offset,tname);*/
cout<<"The flname= " <<flname <<endl;
char cr;
cin>>cr;
return 0;
}
#include <iostream> //输入输出流库函数
#include <string.h> //字符串库函数
int main() //一个返回int型的main函数
{
using namespace std; //这行应放在函数外,作用:避免与函数库在同名
char fname[]="H"; //字符数组 初始化
char sname[]="X"; //...
char tname[]="M"; //...
char flname[80]="asdf"; //...
int offset=0; //定义 并初始为0
strcpy(flname,fname); //把fname的值复制到flname中去
offset=strlen(fname); //计算出fname字符串长度并赋给offset
strcpy(flname+offset," "); //将flanme与offset字符串合并再赋为空
offset+=1; //等价于offset=offset+1
strcpy(flname+offset,sname); //将flanme与offset字符串合并,再将sname赋给合并的字符串
offset+=strlen(sname); //等价于offset=offset+strlen(sname), 将offset与sname长度值相加
strcpy(flname+offset," ");
offset+=1;
strcpy(flname+offset,tname);
cout<<"The flname= " <<flname <<endl; //输出The flanme=字符串,再输出flanme值
char cr; //定义字符
cin>>cr; //输入字符赋给cr
return 0; //主函数返回0
}
肯定不能直接加的,你的变量类型是char,又不是string,尴尬。。。。
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息