#include "stdafx.h" #include <fstream> //必要头文件 #include <string> //必要头文件 #include <iostream> using namespace std; int main(int argc, char* argv[]) { ifstream duqu("11.cpp"); //调用类,读取功能 ofstream xieru("C:\\1.txt"); //调用类,写入功能 string str; while(getline(duqu,str)) //getline 读取一行,循环读取,让getline读取不到为止. { cout<<str<<"\n"; xieru<<str<<"\n"; } return 0; } //第二段 int main(int argc, char* argv[]) { if(argc != 3) { cout<<"用法:.exe -r 文件路径\n"; return 0; } FILE* afile; afile = fopen(argv[2],"r"); if(afile == NULL) { cout<<"打开失败。"; return 0; } if(strcmp(argv[1],"-r") == 0) { char str[100]; memset(str,0,100); //初始化 fread(str,1,100,afile); //读取 cout<<str<<endl; //输出 return 1; } return 1; }
文件读取写入
最新推荐文章于 2023-12-19 19:15:00 发布