Getting fatal error for iostream - c++

I wanted to write a simple clang plug-in. So I just executed a "PrintFunctionNames" plug-in provided in llvm-clang. But when i tried to execute a command :
" clang -cc1 -load ../../Debug+Asserts/lib/libPrintFunctionNames.so
-plugin print-fns some-input-file.c "
it gives me 1 fatal error :
fatal error: 'iostream.h' file not found
#include<iostream.h>
^
1 error generated.
I also tried using -I option providing a path for include directory of 'iostream' but it's still gives me the same error.
I tried it like:
'clang++ -I//usr/include/c++/4.6 -cc1 -load
../../../../Release+Asserts/lib/libPrintFunctionNames.so -plugin
print-fns ak.cpp '
So how do I make this work?

Don't add .h at the end.
#include <iostream>
That should fix it.

iostream belongs to C++ not C. So you should include it as
#include <iostream>
Additionally since you are programming in C++ you should name your source file ending with .cpp not .c to make it clear to the compiler and everyone else, that you want to use C++. Also you might need to invoke clang++ in your first compiler call (but I am not sure about that in context of plugins)

After the C++ language was standardized by the ISO, the header file named iostream.h was renamed to iostream. Change your program to use #include <iostream> instead and it should compile.
You will also need to add using namespace std; statement after each include (or prefix each reference to an iostream function/object with std::).
You can start by using this
#include <iostream>
using namespace std;
Once you are more comfortable with namespaces, you can remove the using statement & instead either use std::cout, std::cin etc or have a
using std::cout;
using std::cin;
etc.

I meet the same question,
template.cpp
g++ template.cpp
compare<int>com1(3,7);
List item
compare<double>com2(12.34,56.78);
compare<char>com3('a','x');
cout<<",the max value:"<<com1.max()<<endl;
cout<<",the max value:"<<com2.max()<<endl;
cout<<",the max value:"<<com3.max()<<endl;
return 0;
the question is up code segment composing not OK, use the shift + table typing next time.

Related

Use clang preprocessor to concatenate C++ source files into one [duplicate]

This question already has answers here:
Merge C++ files into a single source file
(8 answers)
Closed 2 years ago.
In the context of a coding contest, I must copy/paste all my C++ code in a single html input form, the code being compiled remotely. With the code getting bigger, I'd like to split the code into several files.
So, I have several C++ source files, one is main.cc and some others headers such as f.h.
I'd like these source files to be concatenated in a single source file allinone.cc with so that i can compile with clang++ allinone.cc.
I guess this can be achieved using clang preprocessor.
A minimal example would be:
main.cc
#include <iostream>
using namespace std;
#include "f.h"
int main() {
f();
}
f.h
#pragma once
#include <iostream>
using namespacestd;
void f() {
cout <<
}
The closest I could get is with :
clang -E -nostdinc main.cc | grep -v "^#" > allinone.cc
which produces:
#include <iostream>
^~~~~~~~~~
1 error generated.
using namespace std;
using namespacestd;
void f() {
cout <<
}
int main() {
f();
}
The -nostdinc option successfully avoids including code from standard includes. However, the original #include <iostream> disappears and the namespace specification is repeated.
Is there a way to invoke clang preprocessor to achieve the concatenation described in a straight forward manner?
clang -nostdincdoes another thing, not what you expect. This key disables the standard include directories from the include search paths. So, you get the error since the preprocessor is unable to include the file -nostdinc, could not find it in the known include search paths.
What you want is impossible to achieve. You should use cat your files and clean the result manually or use a special software that can remove #include. I suggest you just use a combinations of grep, sort, uniq and place removed and filtered #include into the top of the concatenated file.

How to solve the compiling problems when I use armadillo library'

I'm new in C++ and I tried to use Armadillo to find the eigenvalues of a symmetrical matrix (eig_sym is the function's name). I used 'g++ -std=c++14 main.cpp -o app -O2 -larmadillo -llapack -lbas' and the exit was
error: ‘eig_sym’ was not declared in this scope
eig_sym( eigval, A );
^
eigval_sym.cpp:44:21: note: suggested alternative:
In file included from /usr/include/armadillo:443:0,
from main.cpp:6:
/usr/include/armadillo_bits/fn_eig_sym.hpp:118:1: note: ‘arma::eig_sym’
,but in the main.cpp file I wrote #include . When is the failure? Library path is not found maybe?
just #include <armadillo> is enough to get all functionality from the armadillo library, but do note that everything in armadillo is in the arma namespace. Therefore, you need to either add using namespace arma; in your cpp file or prepend all functions and classes in armadillo with arma::. That is, use arma::eig_sym instead of just eig_sym or add the using directive and continue to write just eig_sym.
This is the same thing you need to do with the standard library, which is in the namespace std. You need to write std::cout and not just cout, unless you add using namespace std;.

There are unresolved includes inside <iostream>

I just tried to compile my C++ code and an error appears when I try to do so.
The error appears on line 9
Here are the versions of the gcc and g++ and such
Any help would be appreciated.
Edit:
I am also including Movie.h:
And also Movie.cpp:
https://puu.sh/vb53G/9e9abd1832.png (I was not able to include more than 3 images due to restrictions)
Firstly, in your Movie.h file, you have not included the string header file correctly. It should be:
#include <string> // without the .h extension
error: 'string' does not name a type
Secondly, you have forgotten to add the closing parenthesis of the constructor function of class "Movie". I am assuming that you have added this now, after the edit
As for the marking done by your compiler, you may find the following StackOverflow post helpful:
StackOverflow Post: Unresolved inclusion iostream.
The link is for the Eclipse IDE, but you can find a similar solution for your own IDE (I cannot tell which one you have).
The line under the #include is just a warning (I'm not sure why).
However, the errors are from the "Movie" class:
1. add "using namespace std" on the top of this class.
2. close the parenthesis on the constructor of 'Movie'.
The error messages are fairly clear:
'string' does not name a type
That is, the compiler is unaware of the type string because either:
you have not #include <string> in Movie.h
or you have, but have not brought it into your namespace with a using namespace std;
although why not just refer to it as std::string?
You are missing
#include <string>

geany: C++ Including libraries and headers

I'm very new in Ubuntu and programming C++ on Ubuntu using Geany.
The problem I have here is that:
the classes i want to iclude to my project will receive an error,
I type,
#include <vector>
the error given here is,
fatal error: vector: No such file or directory
also I cannot use namespace std,
typing using namespace std returns the following error,
error: unknown type name 'using'
Here is the code:
#include <stdio.h> //no problem here
#include "stdlib.h" //no problem here
#include <vector> //this is a problem (lets say it returns error 1)
using namespace std; //this is a problem (lets say it returns error 2)
int main(int argc, char **argv)
{
return 0;
}
This sounds like you are using the wrong compiler to compile your C++ code. For example, by invoking gcc test.cpp the C++ file is actually compiled as C and you receive errors such as the one you posted - there is no vector header in C and there is also no using keyword.
If you are using gcc, the correct way to invoke the compiler to compile C++ is via the g++ symlink, i.e. g++ test.cpp
If you are using clang, the executable is called clang++ instead.
Both compilers support the -x parameter to manually change the language to C++, although in that case you also have to specify that the compiler needs to link your files with the C++ standard library. For example: gcc -x c++ test.cpp -lstdc++

Code::Blocks/ Dev-c++: error: iostream: No such file or directory

I downloaded Code::Blocks from here: http://www.codeblocks.org/downloads/26
I'm learning c programming. When I run the following program, I get error:
iostream: No such file or directory
error: syntax error before "namespace"
warning: type defaults to `int' in declaration of `std'
warning: data definition has no type or storage class
In function `main':
error: `cout' undeclared (first use in this function)
error: (Each undeclared identifier is reported only once
error: for each function it appears in.)
error: `cin' undeclared (first use in this function)
I'm running the following program:
#include <iostream>
using namespace std;
int main()
{
int x;
x = 0;
do {
// "Hello, world!" is printed at least one time
// even though the condition is false
cout<<"Hello, world!\n";
} while ( x != 0 );
cin.get();
}
I tried Dev-C++, I get the same error.
How to fix this?
Is this in a file like "program.c" or "program.cpp"? If it's a .c file, then your compiler may be interpreting it as C, and not C++. This could easily cause such an error. It's possible to "force" the compiler to treat either such extension as the other, but by default, .c files are for C, and .cpp files are compiled as C++.
It's either this, or somehow your default "include" directories for the standard library are not set up right, but I don't know how you'd fix that, as that'd be compiler/environment dependent.
I also had that problem when trying to run my first program in Code::Blocks. My file was saved with '.c' extension as 'test.c' and when I saved it as 'test.cpp', it worked fine.
It is also worth mentioning that I had to restart Code::Blocks before new 'test.cpp' file was compiled successfully.
While saving your source code before compiling just save the name with extension ".cpp". You wont get the error..
I got the same problem.
Change #include < iostream.h >
to #incude < iostream >
Consequently, in your program, change every keyword related to iostream, such as cin cout and endl to std::cout, std::cin and std::endl
That'll do the trick
Use <iostream> instead of <iostream.h>
and add std:: before cout, cin etc
Use std::cout << "Welcome";
instead of cout << "Welcome";
Save the file with .cpp extension
you have missing iostream.h file in you mingw directory folder placed inside codeblocks/devc++. what you have to do is just download the file from link given below and replace with your previous mingw folder in codeblocks/devc++.
http://www.4shared.com/rar/owp-D0Km/mingw.html
I found the problem was cause by having a previous version of cgg and cpp in a Perl installation. The Perl structure did not have the correct library files. When I added C:\MinGW\bin and C:\MinGW\MSYS\1.0\bin to the path, I added them at the end so it picked up the Perl install first. I moved the path variable entries to the beginning and reopened my cmd window and it now works because it finds the MinGW version first.
Type path to see your path environment varialble. Mine now looks like:
C:\MinGW>path
PATH=C:\MinGW\bin;C:\MinGW\MSYS\1.0\bin;C:\Perl\site\bin;C:\Perl\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\WIDCOMM\BluetoothSoftware\;
Apparently you want to create a c++ file. But you allowed your computer to auto provide the file extension C/C++. When it does that it automatically provides a file extension of ".c". Which is not corect. You want ".cpp".
Solution: Rename your file with a ".cpp" extension, or else explicitly state your extension when saving new files by putting ".cpp" (without quotes of course) after your intended file name; i.e. specify your file extension.
I tried in Dev-C++ . Instead of iostream.h use iostream also write the using namespace std;
#include<iostream>
using namespace std;
int main()
{
cout<<"Hello World\n";
return 0;
}
you written your program in C++ code use c code then your program run correctly
in first line use it
#include <Io stream.h>
main ()
{
in ending line use it
system (pause");
You are trying to make a C game right? If you are your code is C++ not C. So if you are trying to make a C game than you should change your code. This might help.
Just put "Using namespace std;" before main() to define the scope of identifiers you are using. This will handle your problem easily.
Try including iostream.h instead of iostream.