在头文件中使用未声明的标识符(Clang)

Axm*_*ill 12 c++ function shared-libraries clang header-files

我正在创建一个函数来读取位于IO.cpp文件中的文件内容:

#include "IO.h"
#include <iostream>
#include <fstream>
IO::IO()
{
    //ctor
}

void IO::readFile(std::string fileName)
{
    std::ofstream inputFile;
    inputFile.open(FileName);
    inputFile >> fileName.toStdString;
    inputFile.close();
    std::cout << fileName;
}
Run Code Online (Sandbox Code Playgroud)

使用头文件IO.h:

#ifndef IO_H
#define IO_H


class IO
{
    public:
        IO();
        void readFile(std::string inputFile);
    protected:
    private:
};

#endif // IO_H
Run Code Online (Sandbox Code Playgroud)

但是我从Clang那里得到了一个错误

include/IO.h | 9 | error:使用未声明的标识符'std'|

我无法弄清楚如何解决它.

Luc*_*ore 22

在解析标头(特别是void readFile(std::string inputFile);行)时,编译器不知道std存在命名空间,更不用说string存在于该命名空间内.

#include <string> 在标题中.