How to use the getline command in c++?

前端 未结 5 1341
难免孤独
难免孤独 2021-02-03 14:22

I\'m trying to turn a cout command into a getline command in c++.

This is my code that I\'m trying to changes....

for (int count=0; count < numberOfEm         


        
5条回答
  •  情歌与酒
    2021-02-03 14:54

    Taking a look at the getline prototype, you'll see that you need two things:

    1. An istream object
    2. A string to for the result
    3. (optionally) the "new line" delimiter (default is '\n'.

    In your case, it seems that the delimiter might be the default: '\n'; if not, you can specify what character separates each value (maybe it's a space ' ' or something). The cin stream would be you istream object, and each of the properties of employees[count] will serve as the second parameter. In summary, getline(cin, employees[count].name); should do the trick.

提交回复
热议问题