dimanche 5 juillet 2020

std::getline does not works inside a function

I have the following function:-

void my_func(std::string b){
        std::string name;
        std::cout << "Please enter the name";
        std::getline(std::cin, name, ',')
        b = name;
        std::cout << "b = " << b << "\n";
}

The problem with this function is when I put it in a header file, the std::getline(std::cin, name, ',') line of the code does not runs ie it does not asks for user input but proceeds printing b. I cannot understand why this is happening.

If I write lines 2 to 6 of my above code in main, it works. But if I put these lines inside a function, it does not works.

Aucun commentaire:

Enregistrer un commentaire