function call not working as i aspect it

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

help.cpp
  char Option;
	cout << endl;
	cout << endl;
	cout << "Options" << endl;
	cout << endl;
	cout << "Type the corresponding number" << endl;
	cout
		<< "1. NormalBlur" << endl
		<< "2. GaussianBlur" << endl
		<< "3. Blend" << endl;
     cin>>Option;
	if (Option == '1')
	{
		Gaussianblur();
	}
gaussian.cpp

cout << "Enter your Image directory " << endl;
getline(cin, imagedir);
cout << endl;
img = imread(imagedir);
if (img.empty())
{
cout << "Error!!!, Invalid image or wrong Directory, check your input and try again, see you later" << endl;
system("pause");
return -1;
}


----------------------------------------------

main.cpp
{
Help();
}


when i run this code after the help.cpp have finish running it is supposed to prompt me to enter my image direct, but it just goes straight to tell me that my input directory is invalid, but it hasnt ask me to input my directory but the the option.... my aim is to get the program to ask me to input my directory after i have pressed one but it is not doing that.., any help we be appreciated

Last edited on
when you do cin>>Option; you leave a '\n' in the input buffer
then the call to getline will capture it, giving you an empty string

http://www.cplusplus.com/reference/istream/ws/
you may do getline(cin>>ws, imagedir); to discard all the whitespace before the user input

or cin>>Option; cin.ignore(); to discard the '\n' after chosing the operation.
thanks boss that works , much thanks
Topic archived. No new replies allowed.