32位随机字符串的产生错误了
#include <iostream>
#include <CTIME>
using std::cout;
const int SIZE_CHAR = 32; //生成32 + 1位C Style字符串
const char CCH[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main()
{
srand((unsigned)time(NULL));
char ch[SIZE_CHAR + 1] = {0};
int len=RAND_MAX/sizeof(CCH);
//产生10个字符串
for(int j=0;j<10;j++)
{
for (int i = 0; i < SIZE_CHAR; ++i)
{
int x = rand() / (sizeof(CCH) - 1);
ch[i] = CCH[x];
}
cout <<ch <<"\n";
}
return 0;
}
int x = rand() / (sizeof(CCH) - 1);
这里不对
[解决办法]
CFile类操作文件默认的是Binary模式在Binary模式下我们必须输入'\r\n',
才能起到回车换行的效果,'\r'只是回车(回到当前行的第一列),
'\n'只是换行(到达下一行的当前列)。