2
    #ifndef MENU_H
    #define MENU_H
    #include <cstring>
    #include <string>
    #include <cctype>
    class Menu{
    public:
    Menu();
    void run();
    int selectOptions();
    void rotate90();
    void rotate180();
    void rotate270();
    void flipVert();
    void flipHoriz();
    void convertHigh(int threshold);
    void saveImage(string saveName);
    void loadImage(string loadName);
    void displayMenu();
    private:
    }
    #endif // MENU_H
C:\Users\Wattenphul\Documents\alg-prog design\project04>g++ -std=c++11 -o main.exe main.cpp menu.cpp

In file included from menu.cpp:6:

menu.h:22:20: error: 'string' has not been declared

     void saveImage(string saveName);

                    ^~~~~~

menu.h:22:35: error: expected ',' or '...' before 'saveName'

     void saveImage(string saveName);

                                   ^~~~~~~~

menu.h:23:20: error: 'string' has not been declared

     void loadImage(string loadName);

                    ^~~~~~

menu.h:23:35: error: expected ',' or '...' before 'loadName'

     void loadImage(string loadName);

                                   ^~~~~~~~

menu.h:28:2: error: expected ';' after class definition

 }

this is the code followed by part of the compilation. It is just the header file the rest of the code hasn't been implemented yet. I do not understand why the string is not working. i tried using the resolution operator as well, but that didn't change the result.

Wattenphul
  • 21
  • 2
  • 4
    There is no `string` in C++, only `std::string`. Either use it explicitly qualified, or add `using std::string;` to explicitly bring it in scope. – Botje Nov 29 '19 at 15:06

3 Answers3

5

It is not called string. It is called std::string.

You may have seen some examples where it was called string. That's because the author took a shortcut and wrong using namespace std somewhere, though we don't necessarily recommend doing that.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
  • More general adding `using namespace` in global space in header files is [invitation for strange build issues](https://stackoverflow.com/a/5849668/1387438). – Marek R Nov 29 '19 at 15:18
0

string is defined inside namespace std, in order to use you need to prefix it with std, so use std::string instead of just string. Alternatively you can avoid prefixing it using using-directive or using-declaration

AshleyWilkes
  • 741
  • 5
  • 13
  • Adding `using namespace std;` into a header file is invitation for complex build issues. Headers mustn't contain `using namespace` in global scope. – Marek R Nov 29 '19 at 15:15
0

Either use std::string instead of string or outside class open namespace "using namespace std;" But as good coding practice, it is not preferred to open namespace at least in .h file.

Build Succeeded
  • 1,153
  • 1
  • 10
  • 24
  • 1
    Adding `using namespace std;` into a header file is invitation for complex build issues. Headers mustn't contain `using namespace` in global scope. [See this](https://stackoverflow.com/a/5849668/1387438). – Marek R Nov 29 '19 at 15:14