g++ error: invalid preprocessing directive #INCLUDE [closed] - c++

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I tried testing MinGW under Windows 7 with a simple Hello World program and got the following errors:
C:\code\helloworld.cpp:2:2: error: invalid preprocessing directive #INCLUDE
C:\code\helloworld.cpp:3:7: error: expected neested-name-specifier before 'namespace'
C:\code\helloworld.cpp:3:17: error: expected ';' before 'std'
C:\code\helloworld.cpp:3:17: error: 'std' does not name a type
C:\code\helloworld.cpp: In function 'int main()':
C:\code\helloworld.cpp:7:2: error: 'cout' was not declared in this scope
My original code was as follows:
//Hello, World
#INCLUDE <iostream>
using namesapce std;
int main()
{
cout << "Hello, world!";
return 0;
}

#include should be lower case. C++ is case sensitive.

It should be lowercase. Use #include.
Also, it's using namespace std; (typo in namespace).

#include <iostream>
using namespace std;
int main()
{
cout << "Hello, world!";
return 0;
}

Related

c++ : invalid operands to binary expression [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 6 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I don't know what's wrong here ?
It's just running errors !!!
#include <iostream>
using namespace std;
int main()
{
cout << string("hello world");
return 0;
}
Read more about C++. So read first Programming -- Principles and Practice Using C++.
Then read C++ reference documentation, notably the one about std::string-s.
You need to #include <string>
You should enable all warnings when compiling. If using GCC, compile with g++ -Wall -g
You don't need that string before the actual string:
#include <iostream>
using namespace std;
int main()
{
cout << "hello world";
return 0;
}
Or, alternatively, if you're trying to store a string:
#include <string>
#include <iostream>
using namespace std;
int main()
{
string str = "hello world";
cout << str;
return 0;
}

"ISO C++ forbids declaration of 'list' with no type" error [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I keep getting the following errors on every line containing list<string> below:
ISO C++ forbids declaration of 'list' with no type
expected ';' before '<' token
#ifndef __REGNAMEGENERATOR_H
#define __REGNAMEGENERATOR_H
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <sstream>
#define Max_reg_Num 1000
using namespace std;
class RegNameGenerator{
private:
int intRegNumber;
int realRegNumber;
list<string> UsedIntReg; // error
list<string> UsedRealReg; // error
public:
RegNameGenerator();
~RegNameGenerator();
string generateIntReg();
string generateRealReg();
list <string> getUsedIntReg(); // error
list <string> getUsedRealReg(); // error
int getIntRegNum();
int getRealRegNum();
};
#endif
You have to include header <list>:
#include <list>

"{" missing function header (old style format list) - expected a declaration [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I'm really really new to C++ and this is my first program on Visual Studio 2015, It shows me 2 errors:
"{" missing function header (old style format list)
expected a declaration
#include "stdafx.h"
#include <iostream>
int main();
{
cout << "Hello World";
return 0;
}
int main() remove ; at the end.
#include "stdafx.h"
#include <iostream>
int main(); // this ';' is giving problem remove it.
{
std::cout << "Hello World"; // use std::cout
return 0;
}

Compile error C++ [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I am new in C++. When I compile this code compiler reports error-
main.cpp-
#include <iostream>
#include <string>
#include "main.h"
using namespace std;
string strings::getstr(string str)
{
return str;
}
int main()
{
strings strstr;
string constr;
string msg;
msg = "Hello World!";
constr = strstr.getstr(msg);
cout << constr;
return 0;
}
main.h-
#ifndef MAIN_H_INCLUDED
#define MAIN_H_INCLUDED
#include <string>
class strings
{
public:
string getstr (string str);
};
#endif // MAIN_H_INCLUDED
error-
error: 'string' does not name a type
error: no 'std::string strings::getstr(std::string)' member function declared in class 'strings'
error: In function 'int main()':
error: 'class strings' has no member named 'getstr'
I am using Code::Blocks and gcc
I have written this simple code because I am working on a project and when I want to compile I always getting
'string' does not name a type
sorry for bad english...
The correct name for the string class is 'std::string' because it is declared within the 'std' namespace (the same goes for 'cout'). After you change 'string' into 'std::string' and use 'std::cout' instead of 'cout' your program will compile correctly.
Another way to do it is to place 'std' the as the first namespace:
#include <string>
using namespace std;
Personally, I don't like to use 'using namespace ...' (It's difficult for me to keep track of different namespaces ).
This could fix the problem
#ifndef MAIN_H_INCLUDED
#define MAIN_H_INCLUDED
#include <string>
class strings
{
public:
std::string getstr(std::string str);
};
#endif // MAIN_H_INCLUDED
use using namespace std; after the header in main.h

main.cpp|45|error: expected primary-expression before "int" and "double" [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
File sys.cpp:
#include <iostream>
#include <stdio.h>
#include <conio.h>
#include <string>
#include <fstream>
using namespace std;
[...]
struct kmph_in_mps
{
int kmph[4];
int result[4];
void kmph_erfassen()
{
for (size_t i = 0; i < 4; ++i)
{
cin >> kmph[i];
}
}
void mps_erfassen(int kmph, double result)
{
result = kmph / 3.6;
}
void ergebniss_ausgeben()
{
cout << endl << kmph << "Km/h sind " <<result << " Meter pro Sekunde\n";
}
};
[...]
File main.cpp:
#include <iostream>
#include <stdio.h>
#include <conio.h>
#include "sys.cpp"
#include <fstream>
kmph_in_mps c;
[...]
void Kmph_in_mps()
{
system("cls");
cout << "\nKm/h: ";
c.kmph_erfassen();
c.mps_erfassen(int kmph, double result);
c.ergebniss_ausgeben();
t.beenden();
}
[...]
Errors:
Error: expected primary-expression before “int”
Error: expected primary-expression before “double”
I am a learning C++, and I dont get what to do now.
I am searching for answers at the internet and here, but I dont realy find the right one.
Which primary expression do I have to write before "in" and "double"?
Or am I doing everything completly wrong, like a beinner does? :P
Edits:
I tryed return result, but it seems to be not allowed in a void.
I already tryed c.mps_erfassen(); but it is gives me an error, too: error: no matching function for call to `kmph_in_mps::mps_erfassen()'|
I already tryed c.mps_erfassen(kmph, result); but then I do not declare them both in this scope. They are declared in the other file (sys.cpp). :S
c.mps_erfassen(int kmph, double result);
//^^^remove int and double
When you call a function, you should not put the type before the parameters.
This
c.mps_erfassen(int kmph, double result);
should be
c.mps_erfassen(kmph, result);
Let function deduce the type :)
EDITED IN RESPONSE TO COMMENT:-
You are creating object of struct in main.cpp while it's definition is in sys.cpp. How would main.cpp would get to know what your struct means.
For better design, place declaration of struct in header file say sys.h, then define required members in .cpp file say sys.cpp ( you have to include sys.h ). And then use that struct in your main.cpp ( again you have to include sys.h over here ).