首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

c++测试程序运行时间遇到的有关问题

2012-09-04 
c++测试程序运行时间遇到的问题C/C++ code#include iostream#include string.h#include stdio.h#inc

c++测试程序运行时间遇到的问题

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 implementationstart1 = 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 implementationstart2 = 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函数都没有啊。
[解决办法]
探讨
LZ ,你main函数都没有啊。

热点排行