乔山办公网我们一直在努力
您的位置:乔山办公网 > word文档 > C++中打开特定路径下的文件 加了#<em>in</em>clude&lt;fstr..

C++中打开特定路径下的文件 加了#<em>in</em>clude&lt;fstr..

作者:乔山办公网日期:

返回目录:word文档


需要用到fstream头文件

用ifstream进行读取

存到变量里面e79fa5e98193e59b9ee7ad94334是需要看需要读取的变量的格式的

例如读取到结构体中就是将变量依次读取存入结构体的每个变量里面

strcut stockType
{
    string personAddress;
    string personCity;
    string personState;
    int personZIP;
};

void addressType :: getData()
{
    ifstream infile;
    
    int index;
    
    string inputFile;
    
    stockType addressTypeList[NO_OF_PERSON];
    
    cout<<"Enter the file path: ";
    cin>>inputFile;    //输入txt文件路径
    cout<<endl;
    
    infile(inputFile.c_str());    //infile按照指定路径读取txt文件

    for(index = 0; index < NO_OF_PERSON; index++)//读取txt文件至struct
    {
        infile>>addressTypeList[index].personAddress;
        infile>>addressTypeList[index].personCity;
        infile>>addressTypeList[index].personState;
        infile>>addressTypeList[index].personZIP;
    }
}


改成ifstream infile("F:\\test\\infile.txt");
\是转义字符
e:\11.jepg  // 应该是 jpeg 格式吧


流操作符>>
如果你这里的word和syn都是前面定义的变量的话:
代码的意思就是
读入word,syn两变量的值
若果不是的话 我也不知道了

相关阅读

关键词不能为空
极力推荐

ppt怎么做_excel表格制作_office365_word文档_365办公网