C++ 组建编译们问题却不能执行,请求指教
try.rar
(960.62 KB)
//TestSuit:Test.h
#ifndef TEST_H
#define TEST_H
#include <string>
#include <iostream>
#include <cassert>
using std::string;
using std::ostream;
using std::cout;
//fail_() has an underscore to prevent colision with ios::fail().For consistency , test_() and succeed_()
//also have underscores.
#define test_(cond) do_test(cond,#cond,__FILE__,__LINE__)
#define fail_(str) do_fail(str,__FILE__,__LINE__)
namespace TestSuite{
class Test{
ostream* osptr;
long nPass;
long nFail;
//Disallowed
Test(const Test&);
Test& operator=(const Test&);
public:
void do_test(bool cond,const std::string& lbl,const char* fname,long lineno);
void do_fail(const string& lbl,const char* fname,long lineno);
public:
Test(ostream* osptr=&cout){
this->osptr=osptr;
nPass=nFail=0;
}
virtual ~Test(){}
virtual void run()=0;
long getNumPassed() const{return nPass;}
long getNumFailed() const{return nFail;}
const ostream* getStream() const{return osptr;}
void setStream(ostream* osptr){this->osptr=osptr;}
void succeed_(){++nPass;}
long report() const;
virtual void reset(){nPass=nFail=0;}
};
}//namespace TestSuite
#endif//TEST_H
//:TestSuite:Test.cpp{0}
#include "Test.h"
#include <iostream>
#include <typeinfo>
#include <vector>
using namespace std;
using namespace TestSuite;
//test_()和fail_() 宏在预处理的时候取得当前文件的文件名和当前行的行号信息,
//并把文件名传递给do_test (),并行号传递给do_fail()这两个函数则显示一个消息并修改相关的计数器。
void Test::do_test(bool cond,const std::string& lbl,const char* fname,long lineno){
if(!cond)
do_fail(lbl,fname,lineno);
else
succeed_();
}
void Test::do_fail(const std::string& lbl,const char* fname,long lineno){
++nFail;
if(osptr){
*osptr<<typeid(*this).name()<<"failure:("<<lbl<<"),"<<fname<<"(line"<<lineno<<")"<<endl;
}
}
long Test::report() const{
if(osptr){
*osptr<<"Test\""<<typeid(*this).name()<<"\":\n\tPassed:"<<nPass<<"\tFailed:"<<nFail<<endl;
}
return nFail;
//Test 类不但保存着成功测试的次数和失败的次数,而且保存着Test::report()显示结果所需的流。
}
class RparseTest:public Test{
//To store the words;
vector<string> strings;
public:
void parseForData(){
//The ';'characters will be delimiters
string s("now.;sense;make;to;going;is;This");
//The last element of the string ;
int last=s.size();
//The beginning of the current word;
size_t current =s.rfind(';');
//Walk backword through the string;
// while(current!=string::npos){
while(current<4294967295){
//Push each word into the vector.
//Current is incremented before copying
//to avoid copying the delimiter:
++current;
strings.push_back(s.substr(current,last-current));
//Back over the delimiter we just found.
//and set last to the end of the next word :
current-=2;
last=current+1;
//Find the next delimiter;
current=s.rfind(';',current);
}
//Pick up the first word-- it's not
//preceded by a delimiter:
strings.push_back(s.substr(0,last));
}
void testData(){
//Test them in the new order:
test_(strings[0]=="This");
test_(strings[1]=="is");
test_(strings[2]=="going");
test_(strings[3]=="to");
test_(strings[4]=="make");
test_(strings[5]=="sense");
test_(strings[6]=="now.");
string sentence;
for(size_t i=0;i<strings.size()-1;i++)
sentence+=strings[i]+=" ";
//Manually put last word in to avoid an extra space;
sentence+=strings[strings.size()-1];
test_(sentence=="This is going to make sense now");
}
void run(){
parseForData();
testData();
}
};
int main(){
RparseTest t;
t.run();
return t.report();
}///:~
求教,是哪里出了问题?
[ 本帖最后由 liuyizhao117 于 2014-3-5 16:58 编辑 ]