I’m a beginner. I don’t know why I can’t use strings. It says string does not have a type.
main.cpp
#include <iostream>
#include <string>
#include "Pancake.h"
using namespace std;
int main() {
Pancake good;
good.setName("David");
cout << good.name << endl;
}
Pancake.h
#ifndef PANCAKE_H
#define PANCAKE_H
#include <string>
class Pancake {
public:
void setName( string x );
string name;
protected:
private:
};
#endif // PANCAKE_H
Pancake.cpp
#include <iostream>
#include "Pancake.h"
#include <string>
using namespace std;
void Pancake::setName( string x ) {
name = x;
}
This only happens when I use strings. When I use a integer and replace string x with int x in all instances of string x it then works. But why?
You’ve simply left out the namespace in your header file:
It might be best to avoid
using namespace ...and instead accept the extra typing with prepending the namespace.