I am creating a function to read the contents of a file, located in an IO.cpp file:
#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;
}
With the header file IO.h:
#ifndef IO_H
#define IO_H
class IO
{
public:
IO();
void readFile(std::string inputFile);
protected:
private:
};
#endif // IO_H
But I get an error from Clang that says
include/IO.h|9|error: use of undeclared identifier 'std'|
And I can't figure out how to solve it.
The identifier is undeclaredIf the identifier is a variable or a function name, you must declare it before it can be used. A function declaration must also include the types of its parameters before the function can be used.
The identifier is undeclared: In any programming language, all variables have to be declared before they are used. If you try to use the name of a such that hasn't been declared yet, an “undeclared identifier” compile-error will occur. Example: #include <stdio.h> int main()
When parsing the header (specifically the void readFile(std::string inputFile);
line), the compiler doesn't know an std
namespace exists, much less string
exists inside that namespace.
#include <string>
in the header.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With