标题:error?
取消只看楼主
cstdio
Rank: 5Rank: 5
来 自:上海市静安区
等 级:贵宾
威 望:15
帖 子:97
专家分:44
注 册:2018-5-30
结帖率:87.5%
已结贴  问题点数:2 回复次数:1 
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;
}
搜索更多相关主题的帖子: std string file int write 
2018-07-13 11:54
cstdio
Rank: 5Rank: 5
来 自:上海市静安区
等 级:贵宾
威 望:15
帖 子:97
专家分:44
注 册:2018-5-30
得分:0 
谢谢

import random
i=random.randint(100,100000)
print i
2018-07-13 14:59



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-488563-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.768801 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved