我从大学开始做这个程序,但是我还有一些在家做的功能:getBirthday
和age
。如何从字符串ID中获取日,月,年的整数值?
我试过仅使用字符串,但不起作用。
#include <iostream>
#include <string>
using namespace std;
enum Sex {male,female,unknown}; //const
class Person //class
{
private:
string name;
string ID; //this is the problem
Sex pol;
....
void getBirthday(int &day,int&month,int&year) //even if i use string for day...it is not working
{}
...
int main()
{Person p1("ALEX","9510167954")...;} //95-year,10-month,16-day*this is what my teacher wrote
我希望输出:16/10/95
最佳答案
尝试如下初始化getBirthday( )
参数:
day = stoi(ID.substr(0,2));
month = stoi(ID.substr(2, 2));
year = stoi(ID.substr(4, 2));