读书人

求纠正一下解决方法

发布时间: 2012-04-02 19:58:59 作者: rapoo

求纠正一下

C/C++ code
#include <iostream>#include <fstream>#include <string>/*********readKeyword(string strLabel, string &strReturn)这个&strReturn不太明白啥用..********/using namespace std;class lOKeyword{private:    string strLabel;    //标签    string *strReturn;    //内容    string strFile;        //路径    ifstream readFile;    //文件    string temp;        //临时public:    lOKeyword();        //初始化    ~lOKeyword();        //释放    int readKeyword(string strLabel, string &strReturn);    //接口};lOKeyword::lOKeyword(){    cout << "请输入路径: ";    cin >> strFile;    readFile.open(strFile.c_str());}lOKeyword::~lOKeyword(){    readFile.close();}int lOKeyword::readKeyword(string strLabel, string &strReturn){    while(readFile >> temp)    {        if(temp == "<"+strLabel+">")        {            temp = " ";        }        if(temp == "</"+strLabel+">")        {            temp = " ";        }        cout << temp << endl;        strReturn = temp;        this->strReturn = &strReturn;    }    this->strLabel = strLabel;    return 0;}int main(){    lOKeyword p;    string one, *two;    cout << "请输入标签: ";    cin >> one;    p.readKeyword(one, *two);    return 0;}


[解决办法]
string &strReturn这个就是个引用。。。就是别名

读书人网 >C++

热点推荐