Click to See Complete Forum and Search --> : Problem With Strings
For some reason this code just will not work, it just repeats itself no matter what you type...
#include <iostream.h>
#include <stdlib.h>
int main()
{
start:
char* pass;
system("cls");
cout<<"Hero Password Protection v2"<<endl;
cout<<"Copyright (C) 2000 Hero Inc. Software"<<endl;
cout<<"By Jake Bush"<<endl;
cout<<" jake_e_bush@hotmail.com"<<endl;
cout<<""<<endl;
cout<<"Password : ";
cin>>pass;
if(pass == "hello")
{
system("cls");
return 0;
}
goto start;
}
any suggestions?
At the time of this writing, no one has even looked at this thread. Does anyone even use C++?
CthulhuDragon
Sep 8th, 2000, 11:20 AM
couple problems with you code. First don't use gotos! Sorry about yelling like that. but in C/C++ goto are really frowned upon. Second you have a character pointer but no memory to point at. You need to actually make a character array. Third, You can't compare a string using == you should use strcmp of one of its brethren. Here is my reworking of your code:
#include <iostream.h>
#include <string.h>//need this for string compare
#include <stdlib.h>
int main()
{
char pass[100];
do
{
system("cls");
cout<<"Hero Password Protection v2"<<endl;
cout<<"Copyright (C) 2000 Hero Inc. Software"<<endl;
cout<<"By Jake Bush"<<endl;
cout<<" jake_e_bush@hotmail.com"<<endl;
cout<<""<<endl;
cout<<"Password : ";
cin>>pass;
}while(strcmp(pass, "hello") !=0);
system("cls");
return 0;
}
This is one of many many ways to do this. This is the closest to your code.
parksie
Sep 8th, 2000, 01:57 PM
In C++, it's often easiest to use the string class from the STL (comes with VC and most other compilers). You need this:
#include <iostream> // NO .H!!!
#include <string>
using namespace std; // V. important
void main() {
string A = "Hello";
string B = "Different";
A = A + " " + B;
cout << A << endl;
}
It's not so important at this stage, but when you get to more advanced things it really helps.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.