Error: C++ requires a type specifier for all declarations

You need to include the string library, you also need to provide a return type for your main function and your implementation may require you to declare an explicit return statement for main (some implementations add an implicit one if you don’t explicitly provide one); like so:

#include <iostream>
#include <string> //this is the line of code you are missing

using namespace std;

int main()//you also need to provide a return type for your main function
{
    string password;
    cin >> password;
    if (password == "Lieutenant") {
        cout << "Correct!" << endl;
    } else {
        cout << "Wrong!" << endl;
    }
return 0;//potentially optional return statement
}

Leave a Comment