c++测试程序运行时间遇到的有关问题
c++测试程序运行时间遇到的问题
报错如下:
[wsl@localhost timecmp]$ g++ -o a timecmp.cpp
timecmp.cpp:9: error: expected constructor, destructor, or type conversion before ‘=’ token
timecmp.cpp:13: error: expected unqualified-id before ‘for’
timecmp.cpp:13: error: expected constructor, destructor, or type conversion before ‘!=’ token
timecmp.cpp:13: error: expected unqualified-id before ‘++’ token
timecmp.cpp:20: error: expected constructor, destructor, or type conversion before ‘=’ token
timecmp.cpp:22: error: expected constructor, destructor, or type conversion before ‘<<’ token
timecmp.cpp:25: error: expected constructor, destructor, or type conversion before ‘=’ token
timecmp.cpp:28: error: expected unqualified-id before ‘for’
timecmp.cpp:28: error: expected constructor, destructor, or type conversion before ‘!=’ token
timecmp.cpp:28: error: expected unqualified-id before ‘++’ token
timecmp.cpp:33: error: expected constructor, destructor, or type conversion before ‘=’ token
timecmp.cpp:35: error: expected constructor, destructor, or type conversion before ‘<<’ token
------解决方案--------------------
LZ ,你main函数都没有啊。
------解决方案--------------------
- C/C++ code
#include <iostream> #include <string.h> #include <stdio.h> #include <time.h> using namespace std; clock_t start1,start2,end1,end2; //C-style character string implementation start1 = clock(); const char *pc = "a very long literal string"; const size_t len = strlen(pc); for (size_t ix = 0; ix != 1000000; ++ix) { char *pc = new char[len + 1]; strcpy(pc2, pc); if (strcmp(pc2, pc)) ; delete [] pc2; } end1 = clock(); cout << "C-style character need "<< end1-start1 << endl; //string implementation start2 = clock(); string str("a very long literal string"); for (int ix = 0; ix != 1000000; ++ix) { string str2 = str; if (str != str2) ; } end2 = clock(); cout << "C-style character need "<< end1-start1 << endl;
报错如下:
[wsl@localhost timecmp]$ g++ -o a timecmp.cpp
timecmp.cpp:9: error: expected constructor, destructor, or type conversion before ‘=’ token
timecmp.cpp:13: error: expected unqualified-id before ‘for’
timecmp.cpp:13: error: expected constructor, destructor, or type conversion before ‘!=’ token
timecmp.cpp:13: error: expected unqualified-id before ‘++’ token
timecmp.cpp:20: error: expected constructor, destructor, or type conversion before ‘=’ token
timecmp.cpp:22: error: expected constructor, destructor, or type conversion before ‘<<’ token
timecmp.cpp:25: error: expected constructor, destructor, or type conversion before ‘=’ token
timecmp.cpp:28: error: expected unqualified-id before ‘for’
timecmp.cpp:28: error: expected constructor, destructor, or type conversion before ‘!=’ token
timecmp.cpp:28: error: expected unqualified-id before ‘++’ token
timecmp.cpp:33: error: expected constructor, destructor, or type conversion before ‘=’ token
timecmp.cpp:35: error: expected constructor, destructor, or type conversion before ‘<<’ token
------解决方案--------------------
LZ ,你main函数都没有啊。
------解决方案--------------------