#ifndef vid
#define vid
#include<cstring>
#include<string>
#include<string.h>
class Video
{
protected:
string title;
int id;
string genre;
string type;
string actor;
bool available;
public :
virtual double rent();
virtual void displayDetails();
};
#endif
I get this error on declaration of all string attributes.
error C2501: 'string' : missing storage-class or type specifiers
Please help
string is defined under std name space, you could fix your code by providing full namespace:
std::string genre;
std::string type;
std::string actor;
string is included in namespace std.
So either qualify the identifier directly as:
std::string
Or use using directive(which should not be preferred for such limited use)
using namespace std;
string str;
Or use a using declaration
using std::string;
string str;
Related
Not really sure what the error is here. This is standard file opening that I've used all the time before. The right things are being included. And it's just a regular ifstream. What is wrong with this?
#include <iostream>
#include <fstream>
#include <sstream>
using namespace std;
int main(){
struct item{
string item;
string type;
int price;
}
ifstream board;
board.open("messageBoard.txt");
}
wow! no one can notice that??!!
int main(){
struct item{ //
string item; // error C2580: redefinition of class name 'item'
string type;
int price;
} // missing a semicolon here `;`
you are using the class name as another identifier so you get a compile-time error redefinition
so you can make them different:
struct Item //
{
string item; // now it's ok Item is not item
string type;
int price;
};
I have this class defined but it doesn't work at all.
#ifndef LIBROS_H
#define LIBROS_H
#include "Articulo.h"
class Libros: public Articulo
{
public:
Libros();
~Libros();
string Autor;
string Editorial;
void mostrar();
void llenar();
};
# endif
this gives:
error
C4430: missing type specifier - int assumed. Note:C++ does not support default-int
You forgot to #include the right header.
#include <string>
And since you have no using statement, you'll need to qualify your strings with the namespace they're in, which is std:
std::string Autor;
std::string Editorial;
Two things:
#include <string>
and the string is in the std namespace. You'll need to use std::string rather than string.
You have to include the string header and you must either prefix string with the namespace std or use a using namespace std;
#ifndef LIBROS_H
#define LIBROS_H
#include <string>
#include "Articulo.h"
class Libros: public Articulo
{
public:
Libros();
~Libros();
std::string Autor;
std::string Editorial;
void mostrar();
void llenar();
};
# endif
I wanna know how should I assign a string to a string member of a struct.
for example :
#include<iostream>
#include<string>
using namespace std;
string c="salam";
struct man{
string name;
}*mary;
int main(){
string b ="HI";
(*mary).name=b;
return 0;
}
It doesn't work but I need this kind of assignment. I have string that I do some operations on it and wanna assign it to one of the members of my struct...
Thanks for your help :)
The problem is not with the string; it is with your attempted use of structures. You created a pointer-to-man, not a man.
Here's how to define a type called man, then create an instance of that type called mary, then assign a value to the member of that type called name:
#include <iostream>
#include <string>
using namespace std;
struct man
{
string name;
};
int main()
{
man mary;
mary.name = "HI";
}
I have this class defined but it doesn't work at all.
#ifndef LIBROS_H
#define LIBROS_H
#include "Articulo.h"
class Libros: public Articulo
{
public:
Libros();
~Libros();
string Autor;
string Editorial;
void mostrar();
void llenar();
};
# endif
this gives:
error
C4430: missing type specifier - int assumed. Note:C++ does not support default-int
You forgot to #include the right header.
#include <string>
And since you have no using statement, you'll need to qualify your strings with the namespace they're in, which is std:
std::string Autor;
std::string Editorial;
Two things:
#include <string>
and the string is in the std namespace. You'll need to use std::string rather than string.
You have to include the string header and you must either prefix string with the namespace std or use a using namespace std;
#ifndef LIBROS_H
#define LIBROS_H
#include <string>
#include "Articulo.h"
class Libros: public Articulo
{
public:
Libros();
~Libros();
std::string Autor;
std::string Editorial;
void mostrar();
void llenar();
};
# endif
I've spent quite a few hours researching and trying to figure out why I'm getting this error. Basically the three files that have to do with the inheriting are CollegeMember.h, Employee.h, and EmpAcademicRecord.h. Employee. is inheriting from CollegeMember.h and EmpAcademicRecord.h is inheriting from Employee.h. Like this CollegeMember <- Employee <- EmpAcademicRecord. The error occurs in EmpAcademicRecord.h. Heres the three files.
CollegeMember.h
#include <cstdlib>
#include <iostream>
#include<ctype.h>
#include<string.h>
#include "Employee.h"
#include "Student.h"
using namespace std;
// ****************************************************************************
// Class Definitions follow
typedef char* String;
// The CollegeMember class
class CollegeMember
{
protected:
int ID_Number;
string FirstName, LastName;
string AddressLine1, AddressLine2, StateProv, Zip;
string Telephone;
string E_Mail;
string answer, answer2, answer3, answer4;//used as sort of booleans for use with validation
// member functions
public:
CollegeMember ( ); // constructor
CollegeMember(const CollegeMember&); //overloaded constructor
void Modify (CollegeMember Member);
void InputData(int x);
string Summary ( ); //summary
string PrintMe(); //fully describes
}; // End of CollegeMember class declaration
Employee.h
#include <cstdlib>
#include <iostream>
#include<ctype.h>
#include<string.h>
#include "EmpAcademicRecord.h"
#include "EmpEmploymentHistory.h"
#include "EmpExtraCurricular.h"
#include "EmpPersonalInfo.h"
#include "EmpPublicationLog.h"
using namespace std;
// ****************************************************************************
// Class Definitions follow
typedef char* String;
// The Employee Class
class Employee: protected CollegeMember
{
float Salary;
protected:
string Department, JobTitle;
// Member Functions
public:
Employee ( ); // constructor
void Modify (Employee ThisEmp);
void InputData(int x);
void SetSalary (float Sal) // Specified as an in-line function
{ Salary = Sal;}
float GetSalary ( ) {return Salary;} // Specified as an in-line function
string Summary ( ); //summary
string PrintMe(); //fully describes
}; // End of Employee class declaration
EmpAcademicRecord.h
#include <iostream>
#include <cstdlib>
#include<ctype.h>
#include<string.h>
using namespace std;
typedef char* String;
class EmpAcademicRecord: protected Employee{ //error occurs on this line
protected:
int ReferenceNumber;
string Institution;
string Award;
string start;
string end;
public:
EmpAcademicRecord();
void InputData (int x);
void Modify(EmpAcademicRecord ThisRec);
void Summary();
};
Any help with this would be greatly appreciated.
That sort of error is usually caused by the type not being defined when you try to use it.
In this case, it appears that you may have included EmpAcademicRecord.h without having first included Employee.h (the includes at the top of the former do not show the latter).
In other words, at the point where the compiler sees:
class EmpAcademicRecord: protected Employee { //error occurs on this line
it has no idea what the Employee class is.
It may be a simple matter of adding:
#include "Employee.h"
to the top of that file, it's a little difficult to be certain since we don't have the code files. In any case, it's certainly a good first step.
Since you have EmpAcademicRecord.h being included by Employee.h, that will probably result in an infinite recursion.
You could fix that with include guards, but I can't see why you need that particulat inclusion. EmpAcademicRecord depends on Employee, not the other way around.