-1

我正在完成这段代码,但我想知道为什么我不能用 ofstream 输出存档。

我做错了什么?

问题出在第 61 行。编译器说:错误,'struct std::stringstream' 没有名为 aux4 的成员。

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include <fstream>
#include <math.h>
#include <iostream>
#include <sstream>



using namespace std;


class  validate { 
       public:
              int aa, mm , dd ;
              string guy;
       public:
              validate ( int x, int y, int z){
                      aa=x; mm=y; dd=z;
              }
       bool check ( int aa, int mm, int dd){
            if ( aa >0){
               if( mm == 01 || mm== 03 || mm == 05 || mm == 07 || mm == 08.0 || mm == 10 || mm == 12){
                   return dd <=31;
                   }
               else if ( mm == 04 || mm == 06 || mm == 09.0 || mm == 11){
                    return dd <=30;
                    }
               else {
                    return dd <=28;
               }
            }
       }
};

int main (){
    int aa, mm, dd, key;
    string name, date, aux1, aux2, aux3;
    stringstream aux4;
    do {

        cout<<"Name:"<<endl;
        cin>>name;
        cout<<"Enter date of birth:"<<endl;
        cin>>date;

        aux1= date.substr(6,9); 
        aa = atoi(aux1.c_str());
        aa=2012-aa;

        aux2= date.substr(3,4);
        aux2=aux2.substr(0,2);
        mm = atoi(aux2.c_str());

        aux3= date.substr(0,2);
        dd = atoi(aux3.c_str());

        aux4 << dd << mm << ".txt";
        ofstream file(aux4.aux4().c_str(), fstream ::app);
        file<<aa<<"years"<<name<<endl;
        file.close();



        cout<<"Enter key != 0 if you want to continue ( Ideally press 1):"<<endl;
        cin>>key;

    }while ( key != 0);
    cout<<"Thanks! End of line."<<endl;

    system ("PAUSE");
    return 0;
};
4

1 回答 1

2

编译器直接指出了问题所在。你可能是这个意思:

aux4.str().c_str()

代替:

aux4.aux4().c_str()

std::stringstream没有aux4()方法。

于 2012-10-03T04:13:01.357 回答