Ich benötige einfachen Kennwort Script, Hilfe??
-
I am horrible at this, I made the changes you suggested and it is still giving me the same error, he makes a good point, I haven't any idea how to define the header.. this will be my first attempt at C++ programming, so sorry for all the lame questions, however I know if I can get this working I will learn alot from it.. so, help is much appreciated..
here's my current attempt:
// kok.cpp : Defines the entry point for the console application. // #include <iostream> #include <string> bool checkPasswd(std::string &password) { if(password == passwd) return true; return false; } int main() { std::cout<<"first login to get the result of 1 + 1 ;): "; std::string userPasswd; std::getline(std::cin,userPasswd); if(checkPasswd(userPasswd)) std::cout<<"\n"<<1 + 1<<"\n"; else std::cout<<"\nAccess Denied!\n"; return 0; }
thanks
-
Would be nice if you post the compile-error-messages!
freshman is right, the string "passwd" isn't defined. Just add this at the beginning from the checkPasswd() function:
std::string passwd = "secret";
Best regards,
SideWinder
-
is this what you meant for me to do:
// kok.cpp : Defines the entry point for the console application. // #include <iostream> #include <string> bool checkPasswd(std::string passwd = "secret"; &password) { if(password == passwd) return true; return false; } int main() { std::cout<<"first login to get the result of 1 + 1 ;): "; std::string userPasswd; std::getline(std::cin,userPasswd); if(checkPasswd(userPasswd)) std::cout<<"\n"<<1 + 1<<"\n"; else std::cout<<"\nAccess Denied!\n"; return 0; }
this isn't working either.. here is my errors:
--------------------Configuration: kok - Win32 Debug--------------------
Compiling...
kok.cpp
C:\Documents and Settings\CodeOne\Desktop\vcZipPw\kok\kok.cpp(6) : error C2143: syntax error : missing ')' before ';'
C:\Documents and Settings\CodeOne\Desktop\vcZipPw\kok\kok.cpp(6) : error C2059: syntax error : ')'
C:\Documents and Settings\CodeOne\Desktop\vcZipPw\kok\kok.cpp(6) : error C2501: 'password' : missing storage-class or type specifiers
C:\Documents and Settings\CodeOne\Desktop\vcZipPw\kok\kok.cpp(6) : error C2239: unexpected token '{' following declaration of 'password'
Error executing cl.exe.kok.obj - 4 error(s), 0 warning(s)
thank you
-
where's the problem?
#include<iostream> #include<string> bool checkPasswd(std::string &password) { std::string passwd = "secret"; if(password == passwd) return true; return false; } int main() { std::cout<<"first login to get the result of 1 + 1 ;): "; std::string userPasswd; std::getline(std::cin,userPasswd); if(checkPasswd(userPasswd)) std::cout<<"\n"<<1 + 1<<"\n"; else std::cout<<"\nAccess Denied!\n"; return 0; }
Compiling...
forumHP.cpp
forumHP.obj - 0 error(s), 0 warning(s)
-
-
thank you very much, I will certainly learn alot from refrencing this script, you guys are awesome, thanks again
-
SideWinder schrieb:
@vR: Du übersetzt aber auch mit Google was
MfG SideWinder
Ne, aber du kannst um diese Uhrzeit nicht von mir erwarten, dass ich schon
gutes Englisch schreibe :D.Oder wuerdest du sagen, dass google es _noch_so_gut_ hinbekommen haette?
mfg
v R
-
freshman schrieb:
@vR: maybe you can tell us also something about the definition of 'passwd'
Die hatte ich in meinem erste Post bereits gegeben ;).
Aber das ist ja jetzt eh egal
mfg
v R
-
@vR n' SideW: warum eigentlich
bool checkPasswd(std::string &password)
und nicht call-by-value oder Übergabe von konstantem Obj (read-only-Bez) ??
-
virtuell Realisticer schrieb:
Die hatte ich in meinem erste Post bereits gegeben ;).
stimmt! Aber es war dein zweiter Post und nicht dein 'erste'
-
"const std::string&" wäre in diesem Fall wohl am Besten. Ein String hat meistens mehr als 4 Zeichen + meistens 4 Bytes für die Länge macht schon 8 Bytes wenn du per value übergibst.
Per Reference sinds nur 4 Bytes und keine aufwendigen Kopieroperationen. Da der String trotzdem nicht verändert werden soll macht man ein const davor.
MfG SideWinder
-
freshman schrieb:
@vR n' SideW: warum eigentlich
bool checkPasswd(std::string &password)
und nicht call-by-value oder Übergabe von konstantem Obj (read-only-Bez) ??Stimmt, ein
bool checkPasswd(const std::string &password);
waere schoener gewesen. call-by-value hab ich nicht gemacht, weil ich es als
unnoetig angesehen habe, dass hier ein Objekt kopiert werden muss.mfg
v R
-
freshman schrieb:
virtuell Realisticer schrieb:
Die hatte ich in meinem erste Post bereits gegeben ;).
stimmt! Aber es war dein zweiter Post und nicht dein 'erste'
Poeh!
mfg
v R
-
virtuell Realisticer schrieb:
Poeh!
Was heißt das?
-
Im Kreuzworträtsel würde man es unter "Ausruf des Erstaunens" finden. Naja vielleicht findet man dort eher "oha", in dem Fall vielleicht "Ausruf des Entsetzens", wobei dass wiederum zu hart für "poeh" ist
MfG SideWinder
-
ich glaube ich hab's; ist es das:
sprech' mal 'Pö' aus mit scharfem P un dkurzem ö
ist es das?
-
freshman schrieb:
virtuell Realisticer schrieb:
Poeh!
Was heißt das?
Du koenntest es so verstehen:
realisticer sieht verachtend an freshman vorbei und geht, mit dem Gedanken im
Hinterkopf, dass man sich die Beziehung zwischen passwd im zweiten und dem im
ersten Post haette denken koennen, weiter:D.
Ok, ich denke das wird zu OT hier, hehe. Gibs zu fresh, du willst mich was
aergern *g*mfg
v R
-
OT==OverTrieben ??
fresh!=frech ??
außerdemist Freitag-Nachmittag, kurz vor Feierabend und da kann man eben nicht mehr so gut denken
-
freshman schrieb:
OT==OverTrieben ??
ne :), aber fuer dich: http://dnq.priggish.de/#charta
fresh!=frech ??
so langsam
außerdemist Freitag-Nachmittag, kurz vor Feierabend und da kann man eben nicht mehr so gut denken
Da stimme ich absolut zu ;).
mfg
v R
-
the script works good and I thank everyone here for helping me immensily.. so thank you immensily
However, I have another question, first here is my \1:
#include<iostream> #include<string> bool checkPasswd(const std::string &password) { std::string passwd = "0x042e"; if(password != passwd) return false; return true; } int main() { std::cout<<"Password: "; std::string userPasswd; std::getline(std::cin,userPasswd); if(checkPasswd(userPasswd)) std::cout<<"\nCorrect! Good job..\n"; else std::cout<<"\nWrong! Try again..\n"; return 0; }
my question is, in the event that someone is wrong, how can I have the script, first tell them they we're wrong, and then to go back to int main(), instead of exiting the app.??
Plus, while in the Visual Studio env. The app works great, but when I use it in my windows env. the app works but when it comes time to output either correct or wrong, it does not pause, but simply closes out.. any ideas why and how to fix these two things I request?? Thank you very much in advance