this is my code:
string getFileContents(istream& file_contents){
string line;
getline(file_contents, line);
return line;
}
project read_project(istream& in){
project newproject;
while(cin){
cout << "Enter your project name: ";
newproject.proname = getFileContents(cin);
cout << "Enter a description: ";
newproject.prodesc = getFileContents(cin);
cout << "How long until deadline: ";
newproject.protime = getFileContents(cin);
promap.insert(pair<string, project> ( newproject.proname , newproject));
cout << endl << "You created a new project: " << newproject.proname
<< endl << "Project description: " << newproject.prodesc ;
}
}
int main(){
string inputcmd;
while (cin){
cout << "TYPE A COMMAND" << endl;
cin >> inputcmd;
if (inputcmd == "makenew")
cout << "MAKING NEW PROJECT";
read_project(cin);
}
return 0;
my objective is to successfully store a project type in a map. the user first enters a 'command' "makefile", this calls a read_project function, which both operate with cin as a parameter. the problem is when i run the code it gives strange outcome, like the first time i type makefile and it skips the "enter your project name: " and does right for the "enter your project description". why does it do that? on all the succeeding loops it works correctly, first asking for the project name and waiting for the input.