从字符串中读取整数
我正在从数据库中读取日期作为字符串。我想将它分解为整数,这样我就可以将它传递给我的 Date 构造函数,所以我使用了以下内容:
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
这是 getDay()
inline int getDay(void) const {return d_;}
问题是 cout 显示整数很好,但是当我将它们传递给我的 Date 构造函数时 输出显示了一堆这样的数字: 1176523603-1162761289-1176531567
你能帮我解决这个问题吗...谢谢!
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 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看上面评论中发布的 Date 类,错误就在这里
删除这两个方法,代码可能会起作用。
Looking at the Date class posted in the comments above the error is here
Delete both of those methods and the code might work.