Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.(5)

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

ITtutoria

ITtutoria Logo ITtutoria Logo

ITtutoria Navigation

  • Python
  • Java
  • Reactjs
  • JavaScript
  • R
  • PySpark
  • MYSQL
  • Pandas
  • QA
  • C++
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Python
  • Science
  • Java
  • JavaScript
  • Reactjs
  • Nodejs
  • Tools
  • QA
Home/ Questions/Ways to resolve the error - c++ requires a type specifier for all declarations.
Next
Answered
Charlie Rodriguez
  • 13
Charlie Rodriguez
Asked: May 17, 20222022-05-17T14:24:44+00:00 2022-05-17T14:24:44+00:00In: cpp

Ways to resolve the error – c++ requires a type specifier for all declarations.

  • 13

. Advertisement .

..3..

. Advertisement .

..4..

I don’t know what I’m doing wrong, but I’ve already lost a couple of days struggling with this. Here is my command line:

#include <iostream>
 
 using namespace std;
 
 main()
 {
  string password;
  cin >> password;
  if (password == "Lieutenant") {
  cout << "Correct!" << endl;
  } else {
  cout << "Wrong!" << endl;
  }
 
 }

This returns:

||=== Build: Debug in Password (compiler: GNU GCC Compiler) ===| /Users/Administrator/Desktop/AppCreations/C++/Password/Password/main.cpp|5|error: C++ requires a type specifier for all declarations| ||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 2 second(s)) ===|.

I don’t have any experience with the “c++ requires a type specifier for all declarations.” In this case, how should I change?

compiler errors
  • 2 2 Answers
  • 206 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook
  • Report

2 Answers

  • Voted
  • Oldest
  • Recent
  • Random
  1. Best Answer
    dttutoria Expert
    2022-06-11T15:34:42+00:00Added an answer on June 11, 2022 at 3:34 pm

    The cause: 
    You’re missing a string library, and the return type for the main function isn’t given. You’ll receive the same problem if you attempt to assign a variable in a class, because you can initialize variables in a class but not assign them later after variable declaration in C++.

    Solution: You must include the string library, as well as give a return type for your main function. Depending on your implementation, you may be required to define an explicit return statement for main, as follows:

    #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
    }
    • 13
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  2. Mila Bouvet
    2022-05-25T20:08:31+00:00Added an answer on May 25, 2022 at 8:08 pm

    It is necessary to declare the return type of main. In legal C++, this should be int In many cases, the return 0; line at the end of your main will be return 0;, i.e. You can exit successfully. Any other 0 can be used to indicate an error condition.

    • 10
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question
  • How to Split String by space in C++
  • How To Convert A Pandas DataFrame Column To A List
  • How to Replace Multiple Characters in A String in Python?
  • How To Remove Special Characters From String Python

Explore

  • Home
  • Tutorial

Footer

ITtutoria

ITtutoria

This website is user friendly and will facilitate transferring knowledge. It would be useful for a self-initiated learning process.

@ ITTutoria Co Ltd.

Tutorial

  • Home
  • Python
  • Science
  • Java
  • JavaScript
  • Reactjs
  • Nodejs
  • Tools
  • QA

Legal Stuff

  • About Us
  • Terms of Use
  • Privacy Policy
  • Contact Us

DMCA.com Protection Status

Help

  • Knowledge Base
  • Support

Follow

© 2022 Ittutoria. All Rights Reserved.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.