well i have a problem here.
when i enter names with leading/trailing spaces they get stored as it is.
how to remove leading/trailing spaces from the strings entered?
Code:
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
vector<string> name_list;
cout << "Enter names or '$' to stop:" << endl;
while (true)
{
string tmp;
// i though this would help, but not. i still get leading spaces.
cin.setf(ios::skipws);
getline(cin, tmp, '\n');
if (tmp == "$") break;
name_list.push_back(tmp);
}
sort(name_list.begin(), name_list.end());
for (int i=0; i<name_list.size(); i++)
{
cout << name_list[i] << endl;
}
return 0;
}