+ -
当前位置:首页 → 问答吧 → 各位哥哥姐姐们帮帮忙啊!!!求一个与c++文件流有关的程序代码,具体要求如下!

各位哥哥姐姐们帮帮忙啊!!!求一个与c++文件流有关的程序代码,具体要求如下!

时间:2011-11-30

来源:互联网

具体要求:
  (1):需要手动输入文件所在的路径!
  (2):程序能够识别输入的路径并且能够对文件进行读写等之类的操作!
  如:我有一个文本文档的路径为d:\\try.txt,则程序需要实现的功能是在我手动输入文件的路径之后能够实现对该文件的读写等操作!

作者: fyk19900503   发布时间: 2011-11-30

你用命令行参数就行了
int main(int args ,char **argv)
{

}

./main ":\\eyr.txt

作者: andy_y39548   发布时间: 2011-11-30

C/C++ code

#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>

using namespace std;

int main()
{
    string filePath;
    cout << "input the file path: ";
    getline(cin,filePath);
    fstream file;
    file.open(filePath.c_str(),ios::in | ios::out );
    if( file.fail() )
    {
        cerr << "file open error,please check the file path if right!" << endl;
        exit(0);
    }
    /*
    *这个地方添加你的度或者写文件操作 注意文件指针的移动用seek实现 具体百度
    */
    file.close();
    return 0;
}



作者: hnuqinhuan   发布时间: 2011-11-30

我很无语呀,这么简单的东西你都懒得做呀。
实在不能支持。
也就是个ReadFile,WriteFile的问题。

作者: Forkerl   发布时间: 2011-11-30