problem with cin and getline

So I have my programs where im trying to use both cin and getline, I know this will bring problems with the >>() but I dontknow how to fix it or make it work.

I input a value for cin but it doesnt get read by the program, it just skips it, here is my code:

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>

using namespace std;

int main()
{
string filename = "message.txt";
string letters;
int numChars(0), i(0), q(0), qcount(0);

ifstream inFile;

inFile.open(filename.c_str());
if (inFile.fail())
{
cout<< "\nThe file was not opened"
<< "\n Check to see if "<<filename<<" exists in the directory"
<< endl;
exit(1);

}


getline(inFile,letters);


inFile.close();
cout<<letters<<endl;
cout<<"\nLook at this message, choose a letter that you would like to change for a space: ";
cin>>q;
numChars = int(letters.length());
for (i=0; i< numChars; i++)
{
if (letters.at(i)=='q')
letters.at(i) =' ';
qcount++;
}
cout<<"new sentence: ";
cout<<"\n\n"<<letters;
cout<<"\n\nThere were "<<qcount<<" "<<q<<" characters in your text."<<endl;
return 0;
}
Topic archived. No new replies allowed.