ba272
asked on
Reading from a command window
Hi,
I need to get a Yes or No from the user, via a command window interface. Anyone know the code to do this?
Thanks,
Bob
I need to get a Yes or No from the user, via a command window interface. Anyone know the code to do this?
Thanks,
Bob
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Example code:
#include <windows.h>
int main(int argc, char* argv[])
{
if (IDOK == MessageBox(NULL, "Enter Click Yes Or No", "Title Yes No", MB_YESNO))
{
//Click yes
}
else
{
//Clicked no
}
return 0;
}
#include <windows.h>
int main(int argc, char* argv[])
{
if (IDOK == MessageBox(NULL, "Enter Click Yes Or No", "Title Yes No", MB_YESNO))
{
//Click yes
}
else
{
//Clicked no
}
return 0;
}
FYI:
You can use IDYES for the comparisson, but IDOK will do the same job.
if (IDYES == MessageBox(NULL, "Enter Click Yes Or No", "Title Yes No", MB_YESNO))
You can use IDYES for the comparisson, but IDOK will do the same job.
if (IDYES == MessageBox(NULL, "Enter Click Yes Or No", "Title Yes No", MB_YESNO))
ASKER
Thanks, I actually needed you first answer, David. And thanks for the addition jkr. But the version of the program i'm working with still uses header files and include statements.
How different will the code:
string Answer;
cout << "Enter yes or no" << endl;
cin >> Answer;
be when using it on an older version of C++?
Thanks,
Bob
How different will the code:
string Answer;
cout << "Enter yes or no" << endl;
cin >> Answer;
be when using it on an older version of C++?
Thanks,
Bob
>>How different will the code be when using it on an older version of C++?
As long as it is ANSI C++ and not some stone age compiler, there won't be any differences. Yet you could still resort to the C version:
char acResponse[255];
printf("Enter Yes or No:");
scanf("%255.255s", acResponse);
if (!_stricmp(acResponse, "Yes")) printf( "Input was YES");
if (!_stricmp(acResponse, "No")) printf( "Input was NO");
As long as it is ANSI C++ and not some stone age compiler, there won't be any differences. Yet you could still resort to the C version:
char acResponse[255];
printf("Enter Yes or No:");
scanf("%255.255s", acResponse);
if (!_stricmp(acResponse, "Yes")) printf( "Input was YES");
if (!_stricmp(acResponse, "No")) printf( "Input was NO");
>>be when using it on an older version of C++?
The above code will work with the older version of C++.
Which compiler and what verison of the compiler?
The above code will work with the older version of C++.
Which compiler and what verison of the compiler?
ASKER
It's the latest actually, but the project I am updated was older, and I didn't expect the "using" statement to work. I'll give it a try. Thanks.
>>I didn't expect the "using" statement to work
It will - VC6 e.g. is from '98 and for sure recognizes it.
It will - VC6 e.g. is from '98 and for sure recognizes it.
Try using AfxMessageBox or MessageBox API function