#include #include using namespace std;

int main() { string input; string name, id; int mark;

while (true) {
    cout << "Type in name;id;mark or Q to stop: ";
    getline(cin, input);

    if (input == "Q") {
        break;
    }

    size_t pos1 = input.find(";"); // find the first semicolon
    size_t pos2 = input.find(";", pos1+1); // find the second semicolon
    name = input.substr(0, pos1); // extract the name
    id = input.substr(pos1+1, pos2-pos1-1); // extract the id
    mark = stoi(input.substr(pos2+1)); // extract the mark and convert to integer

    cout << "Name: " << name << "   ID: " << id << "   Mark: " << mark << endl;
}

return 0;
Write a c++program that repeatedly reads in a line containing a name might be any number of words an ID number 7 digits and a mark separated by semi-colons until the user chooses to quit After each l

原文地址: https://www.cveoy.top/t/topic/hw7L 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录