error?
出了点错误(该程序有C语言成分)#include<iostream>
#include<stdio.h>
#include<string>
using namespace std;
//string filename;
int file();
int file2();
int main(){
std::string choise;
while(1){
std::cout<<"write file or read file?"<<std::endl;
scanf("%s",&choise);
if(choise=="write "){
file();
}
else
file2();
}
return 0;
}
int file(){
FILE *fp;
std::string filename;
int i;
std::cout<<"enter the filename you want to write\n";
//for(i=0;i<8;i++)
scanf("%s",&filename);
fp=fopen(filename,"w");//error
std::cout<<"enter the string that you want to write into the file\n";
std::string writefile;
scanf("%s",&writefile);
fprintf(fp,"%s\n",writefile);
printf("finish write file,file will close and back to main()\n");
fclose(fp);
return 0;
//main();
}
int file2(){
FILE *fp;
std::string filename;
std::string files;
scanf("%s",&filename);
fp=fopen(filename,"r");//error
printf("in %s ,things in the file is\n",filename);
fscanf(fp,"%s",&files);
printf("%s\n",files);
fclose(fp);
printf("finish read file,file will close and back to main()\n");
return 0;
}