main.cpp
来自「对于c++primer中前面几章的练习以及书上的例子」· C++ 代码 · 共 38 行
CPP
38 行
#include <cstdlib>
#include <iostream>
#include<cstring>
using namespace std;
int main(int argc, char *argv[])
{
/* int errors=0;
const char*pc="a very long string";
for(int ix=0;ix<10;++ix)
{
int len=strlen(pc);
char *pc2=new char[len+1];
strcpy(pc2,pc);
cout<<pc2<<endl;
if(strcmp(pc2,pc))
++errors;
delete []pc2;
}
cout<<"c_style character strings:"<<errors<<"errors occurred.\n";*/
int errors=0;
string str("a very string");
for(int ix=0;ix<1000000;++ix)
{
int len=str.size();
string str2=str;
if(str!=str2)
++errors;
cout<<str2<<endl;
}
cout<<"c_style character strings:"<<errors<<"errors occurred.\n";
system("PAUSE");
return EXIT_SUCCESS;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?