c++ - 我不明白尝试使用字符串作为函数参数时遇到的错误

标签 c++ string compiler-errors g++

    #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

 }

这是编译后的代码。这只是头文件,其余代码尚未实现。我不明白为什么该字符串不起作用。我也尝试使用解析运算符,但这并没有改变结果。

最佳答案

它不被称为字符串。它被称为std::string

您可能已经看到过一些将其称为字符串的示例。那是因为作者走了一条捷径,并在某处错误地使用了命名空间 std,但 we don't necessarily recommend doing that .

关于c++ - 我不明白尝试使用字符串作为函数参数时遇到的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59107135/

相关文章:

java - Long.toString(i) 与 i + ""之间的区别

c++ - 试图编译 boost 依赖库 - "is private"错误

java - Visual Basic,预期语句结束 - 数组?

c++ - SFML loadFromFile 不显示图像

c++ - 没有正确读取字符串

c++ - 遍历行时如何只保留最后一个重复项

c++ - 如何在 C/C++ 中对字符串应用掩码?

c++ - Windows Linux C++编译问题: "no matching function for call"

c++ - 如何运行代码循环 if (a==b) 并且如果 a != b 没有 "else"则不循环

c++ - 零星碰撞检测