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 解决一个加好友限制问题 或者有好的方案
  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥30 求解达问题(有红包)