mardi 26 octobre 2021

How do I insert user input variables into same spot in vector

//Main driver

int main(){

//If I run the code below.

    vector<string> A = {"My name is Muzaib.\n Hello"};
    cout << A[0];

//It will print My name is Muzaib

// Hello

//But what I want to know is how do I do the same but with user input?

string name, age;
cout << "Enter name: ";
getline(cin,name);
cout << "\nEnter age: ";
getline(cin,age);
vector<string> B = {"name \n age"}  //remember I want it in the same spot.
cout << B[0]

​ return 0; }

Aucun commentaire:

Enregistrer un commentaire