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
Related
I am wondering why I am getting error "string could not be resolved to type" when I have the proper inclusions?
#ifndef EVENTFILEREADER_H_
#define EVENTFILEREADER_H_
#include <string>
#include <stdlib.h>
#include <iostream>
class EventFileReader {
public:
EventFileReader(string fileName);
virtual ~EventFileReader();
};
#endif /* EVENTFILEREADER_H_ */
Your compiler is complaining about not being able to find string as a defined type.
You should add its namespace std:
EventFileReader(std::string fileName);
^^^^^
You need to specify namespace, e.g.
std::string
or put the using declaration after includes:
using std::string;
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 have these two header files and one produces an error if I don't put std:: in front of all string declarations and the other doesn't. I was just wondering what the difference between the two was.
The following will produce an error if the std:: is not in front of the string declarations:
#include <string>
#include <vector>
#pragma once
#ifndef DATABASE_H
#define DATABASE_H
struct Item
{
public:
std::string object;
int numOfColors;
std::string colors;
int sizeSmall;
int sizeLarge;
};
class database
{
private:
void fillDatabase(std::vector<Item>);
public:
void getDatabase(std::vector<Item>);
};
#endif
The following code will not produce an error:
#include <string>
#pragma once
#ifndef GUISTRUCT_H
#define GUISTRUCT_H
struct guiValues
{
public:
string shape;
string color;
int width;
double squareProbability;
double rectangleProbability;
double circleProbability;
string firstMostLikelyObject;
double FMLOprobability;
string secondMostLikelyObject;
double SMLOprobability;
string thirdMostLikelyObject;
double TMLOprobability;
};
#endif
The second file is included after some other that defines
using namespace std;
string is declared in the namespace std. So one needs to use the namespace std to make use of string. it can be done in two ways:
By explicitly mentioning which type(string in this case) you want to include from the std namespace as in case 1, std::string colors
OR
By enabling the entire std namespace, using namespace std; which imports all types from the namespace in your global namespace.(Please note that Doing this in headers is not recommended)
In the second case seems you have included the entire std namespace before the particular include and hence it is not giving an error even without exlpicit mention of std::String
how can I divide the header and implementation of a global function?
My way is:
split.h
#pragma once
#include <string>
#include <vector>
#include <functional>
#include <iostream>
void split(const string s, const string c);
split.cpp
#include "split.h"
void split(const string& s, const string& c){
...
}
main.cpp
// main.cpp : Defines the entry point for the console application.
//
#include <string>
#include <vector>
#include <functional>
#include <iostream>
#include "stdafx.h"
#include "split.h"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
vector<string> v;
string s = "The;;woraaald;;is;;not;;enoaaaugh";
string c = " aaa ;; ccc";
split(s,c);
return 0;
}
And errors are:
Error 1 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ...\split.h 8
Error 2 error C2146: syntax error : missing ',' before identifier 's' ...\split.h 8
How can I solve this problem? thx
In header file use std:: namespace qualifier - std::string
In the header file, you have to give the fully qualified name std::string. In the source files, you can add using namespace std; or using std::string; and then just spell it string.
Also, you've declared the function taking arguments by value, but defined it taking arguments by reference.
At least one problem is, you are missing the 'std::' namespace qualifier in split.h:
#pragma once
#include <string>
#include <vector>
#include <functional>
#include <iostream>
void split(const std::string s, const std::string c);
I think you either forgot to put using std::string; before split declaration or use std::string const& as split parameter declarations.
Also split declaration mismatch from split definition string const vs string const&
i can't get rid of these errors... i have semicolons everywhere i checked...
the code is simple:
the error takes me to the definition "string name" in article.h...
main.cpp
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
using namespace std;
#include "article.h"
int main()
{
string si;
char article[128];
vector<Article> articles;
ifstream file;
file.open("input.txt",ifstream::in);
while(!file.eof())
{
file.getline(article,128);
articles.push_back(Article(article));
}
file.close();
while(1);
return(1);
}
article.h:
#ifndef Article_H
#define Article_H
class Article
{
public:
int year;
string name;
Article(char *i_name);
};
#endif
You should add:
#include <string>
to your "article.h" header file and declare name like this:
std::string name;
It seems the string type is not defined in the artivle.h file. Try to include iostream and add using namespace std (or write std::string instead of using namespace)
You should use the std:: namespace prefix in the header, like
std::string name;