0

crashing program

my program keeps crashing can you help? heres the code: #include<iostream> #include<stdio.h> int main() { char* a; using namespace std; cin>>a; if(a=="logan") { cout<<"granted"; } else{ cout<<"denied"; } return 0; }

11th Dec 2016, 3:32 AM
Logan Minaudo
Logan Minaudo - avatar
5 Respuestas
+ 3
using namespace std; needs to be in with all the header files, not inside main. #include <iostream> using namespace std; int main() { }
11th Dec 2016, 3:38 AM
Cohen Creber
Cohen Creber - avatar
+ 1
char can contain only one character. therefore it crashes I guess
11th Dec 2016, 7:08 AM
Sandeep Chatterjee
+ 1
char* is a used to iterate through a character array, there is nothing wrong with what he has written here. It generates a compile error because of the header file being inside the main, c'mon guys.
11th Dec 2016, 8:57 AM
Cohen Creber
Cohen Creber - avatar
0
I don't think u can input value for pointer .
11th Dec 2016, 4:09 AM
Bibek Ghimire
Bibek Ghimire - avatar
- 2
hey mlg, use this code #include<iostream> #include<string> using namespace std; int main() { string mycode; cout<<"enter code"; cin>>mycode; //or use if(mycode=="Logan") if (mycode.compare("Logan")) cout<<"granted"; else cout<<"denied"; return 0; }
11th Dec 2016, 4:20 AM
Morpheus
Morpheus - avatar