C++ ifstream 从文件中 字符串和数字混合输入

读入数据类似字符串+数字+字符串+数字这样循环穿插混合的类型

比如下面的代码,main函数里有个while循环,无限刷菜单然后用户输入选项的那种,一开始使用freopen会导致缓冲区无限有数据,即无法继续输入选项了就

采用ifstream来解决,注释掉的是之前的会出问题的freopen版本的代码


#include
#define N 50
#define M 50
#define W 50
#define Pi acos(-1.0)
#define clr(a) memset(a,0,sizeof a)
#define space(a) for(int i=0;i>s_num>>m_num>>w_num){
        cout<>m_item[i].name;
            //scanf("%s",m_item[i].name);
            cout<>m_item[i].no[j];
                //scanf("%d",&m_item[i].no[j]);
                cout<>w_item[i].name;
        //scanf("%s",w_item[i].name);
        cout<>w_item[i].no[j];
            //scanf("%d",&w_item[i].no[j]);
            cout<>option;
        switch(option)
        {
        case 1:mod1();break;
// 添加相应代码
        case 0:
            exit(0);
        default:
            cout<<"输入选项不正确!请重新输入!"<

你可能感兴趣的:(C++文件操作,ifstream,字符串和数字混合输入,C++,freopen)