Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get last string using c++ OOP

How its possible to get last two strings from PIN, without using char, really don`t have any idea, i need it because, my program will select men or women with that last two strings…

#include "CWorker.h"
#include <iostream>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <conio.h>
using namespace std;

void CWorker::setData() {
    cin.ignore();
    cout << "\tEnter name of the employee: "; getline(cin, name);
    cout << "Enter Personal Identity number: "; getline(cin, PIN);
    cout << "Enter daily peyment for the employee: "; cin >> dailyPayment;
    cout << "Enter work days for the employee: "; cin >> workDays;
}
void CWorker::getData() {
    cout << "\tName of the employee: " << name << endl;
    cout << "Personal id. number on the employee is: " << PIN << endl;
    cout << "Daily payment for the employ1ee: " << dailyPayment << endl;
    cout << "Work days for the employee: " << workDays << endl;
}
void CWorker::pin();

i share only part of my CPP fail but rly i had no idea how to deal with this function pin.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I guess PIN is a string. To get the last 2 digits

 std::string last2 = PIN.substr(PIN.length() - 2, 2);

if PIN is a number then do

 string PINs = std::to_string(PIN);
 std::string last2 = PINs.substr(PINs.length() - 2, 2);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading