So basically I want to convert a birth date, set to integers, and I want to convert it into a string. I recently got into object programming and created a method that would convert the date of birth into a string to print it
User.h
#pragma once
#include <string>
#include <iostream>
using std::cout;
using std::string;
class User
{
private:
string name;
string surname;
string place_birth;
int day;
int month;
int year;
public:
//setter e getter del name, surname, place birth and birth date
User();
User(string name, string surname, string place_birth, int day, int month, int year);
//Getter date birth
string get_date_birth();
//getter del palce birth
string get_pbirth();
//get user date
string get_User_Date();
};
---------------------------------------------------------
User.cpp
#include "Utente.h"
User::User(){
this-> name=" ";
this-> surname=" ";
this-> place_birth=" ";
this-> day=0;
this-> month=0;
this-> year=0;
}
User::User(string nome, string cognome, string luogo_nascita, int gg, int mm, int aa){
this->name=name;
this->surname=surname;
this->place_birth=place_birth;
this->day=day;
this->month=month;
this->year=year;
}
string User::get_date_birth(){
return "Date of birth>> " + std::to_string(this->date) + "/" + std::to_string(this->month) + "/" + std::to_string(this->year);[/b][/b][/b]
}
std::string User::get_pbirth(){
return place_birth;
}
string User::get_User_Date(){
cout<<"name>> "<<this->name<<std::endl;
cout<<"surname>> "<<this->surname<<std::endl;
cout<<"place of birth>> "<<this->place_birth<<std::endl;
return 0;
}
when i want print get_date_birth he take me this
terminate called after throwing an instance of 'std::logic_error'
what(): basic_string::_M_construct null not valid