fortunetoday 2021-09-19 18:31 采纳率: 100%
浏览 461
已结题

求看一下啊c++ ifstream读取文件为何失败

#include<iostream>
#include<fstream>
using namespace std;
int main()
{
    char ch1;
    ofstream outFile("d:\\vs c++ document\\first-35\\file1.txt",ios::out);
    if(!outFile)
    {cout<<"文件打开错误!";return 0;}
    outFile<<"I am a file.Please read me.";
    cout<<"文件内容I am file.Please read me."<<endl;
    outFile.close();
    ifstream inFile("d:\\vs c++ doucument\\first-35\\file1.txt",ios::in);
    if(!inFile)
    {cout<<"文件打开错误!";goto Exit;}
    streampos pos=inFile.tellg();
    cout<<"当前文件指针位置:"<<pos;
    inFile.get(ch1);  cout<<",字符"<<ch1<<endl;
    pos=inFile.tellg();
    cout<<"读取一个字符后文件指针位置:"<<pos<<endl;
    inFile.seekg(5,ios::beg);
    pos=inFile.tellg();
    cout<<"后移5个字符后文件指针位置:"<<pos;
    inFile.get(ch1);  cout<<",字符"<<ch1<<endl;
    pos=inFile.tellg();
    cout<<"读取一个字符后文件指针位置:"<<endl;
    pos=pos+(streampos)19;
    inFile.seekg(pos);
    cout<<"后移19个字符后文件指针位置:"<<pos;
    inFile.get(ch1);cout<<",字符"<<ch1;
    inFile.get(ch1);cout<<ch1<<endl;
    inFile.close();
    
Exit:
    return 0;
}


程序在ifstream那里读取文件失败。

  • 写回答

1条回答 默认 最新

  • 快乐鹦鹉 2021-09-19 18:45
    关注

    "d;\vs c++ d

    d后面应该是冒号,你写成分号了

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 9月27日
  • 已采纳回答 9月19日
  • 修改了问题 9月19日
  • 创建了问题 9月19日