I have this problem in my program! I need a function that fixes the input. If the string has white characters at the beginning. For example : if s=" hello" , i want to fix the string to be : "hello". I made this function fix_input but it seems to have a problem. Any ideas??
Thank you
Crashgr
void fix_input(string &s)
{
string tmp;
int i=0;
while (s.at(i)==' ')
i++;
while(i<=s.length())
{
tmp+=s.at(i);
i++;
}
s=tmp;
}
int main()
{
string input;
getline(cin,input);
if(!input.empty())
{
if (input.at(0)==' ')
fix_input(input);
cout<<input<<endl;
}
return 0;
}