My header file seems to be correct but it is throwing a lot of errors

Viewed 44

I am writing an interface program and I am using classes to write the interface as well as some of the other options within the program. This is what I have written so far:

#ifndef INTERFACE_H
#define INTERFACE_H 

#include <iostream>
#include <vector>
#include <string> 

class Interface
{
private:
    typedef vector<string> programType;
    programType programCode;
    
public:
    void startInterface()
    {
        char q, input;
        do
        {
            cout << "PySUB Interpreter 1.0 on Windows (September 2020)" << endl;
            cout << "Enter program lines or read(<filename>.py) at command line interface" << endl;
            cout << "Type 'help' for more information or 'quit' to exit" << endl;
        } while (input != q);
    }

    void quit();
    void help();
    void show();
    void clear();
};

#endif

The errors that I am getting are:

Build started...
1>------ Build started: Project: pysub1, Configuration: Debug x64 ------
1>interface.cpp
1>C:\Users\Johnathon\source\repos\pysub1\pysub1\interface.h(11,16): error C2143: syntax error: missing ';' before '<'
1>C:\Users\Johnathon\source\repos\pysub1\pysub1\interface.h(11,16): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Users\Johnathon\source\repos\pysub1\pysub1\interface.h(11,36): error C2238: unexpected token(s) preceding ';'
1>C:\Users\Johnathon\source\repos\pysub1\pysub1\interface.h(12,14): error C3646: 'programCode': unknown override specifier
1>C:\Users\Johnathon\source\repos\pysub1\pysub1\interface.h(12,25): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Users\Johnathon\source\repos\pysub1\pysub1\interface.h(21,72): error C2065: 'endl': undeclared identifier
1>C:\Users\Johnathon\source\repos\pysub1\pysub1\interface.h(22,91): error C2065: 'endl': undeclared identifier
1>C:\Users\Johnathon\source\repos\pysub1\pysub1\interface.h(23,73): error C2065: 'endl': undeclared identifier
1>Done building project "pysub1.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

How do I resolve this?

1 Answers

The problem here is that you don't specify the namespace of cout, endl, etc. You should either change them them to std::cout and so on, or write using namespace std at the top of your file (which is generally considered bad practice, but will do just fine in your example).

Related