标题:string对象不能作为函数参数进行传递吗?
取消只看楼主
hsnr
Rank: 1
等 级:新手上路
帖 子:83
专家分:0
注 册:2010-4-4
结帖率:90.32%
 问题点数:0 回复次数:0 
string对象不能作为函数参数进行传递吗?
// 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;
}
搜索更多相关主题的帖子: string 函数 参数 对象 
2010-05-14 14:46



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-306654-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.020219 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved