I have the following function:-
void my_func(std::string b){
std::string name;
std::cout << "Please enter the name\n";
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.
#include <iostream>
#include <string>
int main(){
std::string name, b;
std::cout << "Please enter the name\n";
std::getline(std::cin, name, ',')
b = name;
std::cout << "b = " << b << "\n";
return 0;
}