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
You can use getline function that takes input stream as first argument. It's prototype looks like this: basic_istream<...>& getline(basic_istream<...>& _Istr, basic_string<...>& _Str)
But then you have to think about that you are dealing with std::string
and parse it as a type that you actually need (char*
, int
, whatever):
#include
#include
#include
using namespace std;
//...
for (int count=0; count < numberOfEmployees; count++)
{
string name, title, sSSnum, sSalary, s;
cout << "Name: ";
getline(cin, name);
employees[count].name = name.c_str();
cout << "Title: ";
getline(cin, title);
employees[count].title = name.c_str();
cout << "SSNum: ";
getline(cin, sSSnum);
istringstream is(sSSnum);
is >> employees[count].SSNum;
cout << "Salary: ";
getline(cin, sSalary);
is.clear();
is.str(sSalary);
is >> employees[count].Salary;
//...
}