Is there anyway using string name to quit program.
by using number in string to quit program.
for example :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
int const limit=100;
string name[limit];
cout<<"Enter 00 to terminate."<<endl;
for(i=0; i<limit; i++)
{
cout<<"Enter name: ";
cin.ignore();
getline(cin,name[i]);
if(name[i]==00)
{
break;
}
system("Pause")
return 0;
}
|
for some reasons i know that
does not match the operand. is there way by using integer in string to quit the program?
Last edited on
name[i]
is a string. Thus you need to compare it with a string. "00" rather than 00.
Last edited on
Hello DesmondLee,
Put the if statement after the getline for name i.e., move lines 23 - 26 to line 21.
Hope that helps,
Andy
Thanks @Handy Andy.. its works :)