Hi everyone. I'm new to this forum and also new to the world of C++. Allthough I some knowledge about it. Okay so i'm getting confused in characters in c++. I want to make a program that will read my password and if its correct, it will excute the rest of the code. I will try to give a rough example:
So my password for example is "cplusplus". When i type in "cplusplus", the program would show me "Welcome".
you would want to read in a string using the std::cin object and test if it matches your word. A quick example would be:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <iostream>
#include <string>
const std::string PASSWORD = "cplusplus"; //define your constant
int main()
{
std::string Temp; //this string holds user input
std::cout << "Enter the secret password: "; //ask for input
while(Temp != PASSWORD) //run this loop while the password is incorrect
{
std::cin >> Temp //this line takes in input from the console
//and is stored in the string
}
std::cout << "Correct! now executing program...";
// your code here
return 0;
}
For the library problem, you can try <string.h>, <String>, <cstring> and <String.h>. One of those should work, probably string.h, but if in case it doesn't, try the others.
Open a cpp file or create one, when making a file or project you need to select C/C++ -> C++, and choose where to create it. It's simple, has a nice IDE, try to get used to it! :D