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

求看一下啊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日

悬赏问题

  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助