注册 登录
编程论坛 C++教室

string对象不能作为函数参数进行传递吗?

hsnr 发布于 2010-05-14 14:46, 1248 次点击
// Input all basic data of this c++ program

void InputBasic(string IfStr,string OfStr)
{
    ifstream inputfile;
    cout<<endl;
    cout<<"请输入第一个基本数据(输入)文件名"<<endl;
    cin>>IfStr;
    cout<<endl;
    inputfile.open(IfStr.c_str());
    if(inputfile.fail())
    {
        cout<<"第一个基本数据(输入)文件无法打开"<<endl;
        cout<<endl;
        exit(1);
    }

//
    ofstream outputfile;
    cout<<"请输入第一个基本数据(输出)文件名"<<endl;
    cin>>OfStr;
    cout<<endl;
    outputfile.open(OfStr.c_str());
    if(outputfile.fail())
    {
        cout<<"第一个基本数据(输出)文件无法打开"<<endl;
        cout<<endl;
        exit(2);
    }
   ...............

    inputfile.close();
    outputfile.close();
    return;
}

void InputBasicData(string IfStr,string OfStr)
{
    ifstream inputfile;
    inputfile.open(IfStr.c_str(),ios_base::in|ios_base::app);
    inputfile.seekg(8*sizeof(int)+2*sizeof(double), ios::beg);
    if(inputfile.fail())
    {
        cout<<"基本数据(输入)文件无法打开"<<endl;
        exit(2);
    }
//
    ofstream outputfile;
    outputfile.open(OfStr.c_str(),ios_base::out|ios::app);
    if(outputfile.fail())
    {
        cout<<"基本数据(输出)文件无法打开"<<endl;
        exit(2);
    }
    ..............

    inputfile.close();
    outputfile.close();

    return;
}
int _tmain(int argc, _TCHAR* argv[])
{
    string IfStr,OfStr;
    data.InputBasic(IfStr,OfStr);
    cout<<IfStr<<OfStr<<endl;// 不能输出!
    data.InputBasicData(IfStr,OfStr);
   ................
    return 0;
}
0 回复
1