#include<iostream>
using namespace std;
int main()
{
cout << sizeof("C program") << endl;//10,'\0'会占据一个字节
return 0;
}
#include<iostream>
using namespace std;
int main()
{
cout << "He said:\"I am a stu\\dent.\"" << endl;
return 0;
}
#include<iostream>
#include<cstring>//strcmp,strcpy
using namespace std;
int main()
{
char title[] = "Prison Break";//title最后一个元素为‘\0’
char hero[100] = "Michael Scofied";
char prisonName[100];
char response[100];
cout << "What's the name of the prison in" << title << endl;
cin >> prisonName;
if(strcmp(prisonName, "Fox-River")==0)
cout << "Yeah! Do you love " << hero << endl;
else
{
strcpy(response, "It seems you haven't watched it!\n");
cout << response;
}
title[0] = 't';
title[3] = 0;//0相当于'\0','\0'的ASCII码为0
cout << title << endl;
return 0;
}
【strcmp】C/C++函数,比较两个字符串
设这两个字符串为str1,str2,
若str1==str2,则返回零;
若str1<str2,则返回负数;
若str1>str2,则返回正数。
如:
strcmp(“abcd”,”abcd”)的返回值是 0;
strcmp(“abcd”,”dcba”)的返回值是 -1;
strcmp(“dcba”,”abcd”)的返回值是 1;
按照字典序比较。
参考链接:https://blog.csdn.net/u011028345/article/details/76571569
【strcpy】 参考链接:https://blog.csdn.net/jiangliuzheng/article/details/8440085