开发者

reading an integer from a string

I am reading a date from the db as a string. I want to break it down into integers so I can pass it to my Date constructor, so I used the following:

 int y,m,d;
sscanf(test,"%d-%d-%d",&y,&m,&d);
cout<<"date is: "<<y<<"-"<<m<<"-"<<d<<"\n";
Date cdr;
    cdr=Date(d,m,y);
    setDate(cdr);
cout<<"cdr is "<<cdr.getDay();//this is returning 0

and here's the getDay()

inline int getDay(void) const {return 开发者_StackOverflow中文版d_;}

the problem is the cout shows the integers fine, but when I pass these to my Date constructor the output shows a bunch of numbers like this: 1176523603-1162761289-1176531567

can you help me fix this...thx!


Looking at the Date class posted in the comments above the error is here

class Date
{
...
Date(const Date& dd){}
Date& operator=(const Date&){}
...
};

Delete both of those methods and the code might work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜