#include <iostream>
using namespace std;
int main()
{
char str1[100] = "ab\0cdddddddddd";
cout << str1 << endl;
FILE *fa = fopen("a.txt", "wb");
fwrite(str1, sizeof(str1), 1, fa);
fclose(fa);
char str2[100] = "ab";
cout << str2 << endl;
FILE *fb = fopen("b.txt", "wb");
fwrite(str2, sizeof(str2), 1, fb);
fclose(fb);
if(0 == strcmp(str1, str2))
{
cout << "yes" << endl;
}
else
{
cout << "no" << endl;
}
return 0;
}
小程序分享:str1和str2对应的串相等, 但是a.txt和b.txt不相同。
本文转载:CSDN博客