This question already has answers here:
fatal error: iostream.h no such file or directory [duplicate]
(3 answers)
Closed 6 years ago.
I am using Windows 8.1 and Dev C++ and I have the following code:
#include<iostream.h>
main()
{
cout<<"welcome to devc++";
system("pause");
}
The syntax is correct, but I get an error that says:
[Error] iostream.h: No such file or directory
I have tried to change to location of this .cpp folder, watched video tutorials, but I could not point out why I am getting this error and how to remove it.
You need to use #include<iostream> instead of #include<iostream.h>. The later one has been deprecated now; which is why you face the error. More details here.
Besides, main() being a function, should have a return type. So, you should write int main() and not just main().
Just do,
#include <iostream>
instead of
#include <iostream.h>
because, as C++ progressed from specific implementation to standard one,.h were deprecated from he library.
In addition to changing to
#include <iostream>
You can also add
using namespace std;
before main if you want to use cout without having to use std::cout.
Related
This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 9 months ago.
I'm trying to use the library octomap and have installed according to the instructions in their GitHub. However, when I try to build and run this simple code with VSCode build task (with g++) I get the error: undefined reference to `octomap::OcTree::OcTree(double)' and other undefined references to Octomap related code. VSCode recognizes that the library is installed (it suggests it when I type #include <...> ) and gives me more information about the octomap functions when I hover over them.
#include <iostream>
#include <octomap/octomap.h>
#include <octomap/OcTree.h>
using namespace std;
int main()
{
octomap::OcTree tree(0.1);
cout << "Hello, World!! \n";
return 0;
}
Octomap header files are in /usr/local/lib/octomap/octomap/include/octomap from what I can tell. I haven't coded with C++ a lot, so this might be just a newbie mistake that I'm missing. I've tried several approaches but still can't get it to work. What am I missing here?
Thanks in advance.
your problem is the program wasn't linked with octomap library
use cmake and include some lines like:
find_package(octomap REQUIRED)
include_directories(${OCTOMAP_INCLUDE_DIRS})
target_link_libraries(${OCTOMAP_LIBRARIES})
or from command line with g++ <source files> -loctomap -loctomath
refer : http://wiki.ros.org/octomap
This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 7 years ago.
I'm basically trying to instantiate an object from a class in c++ and use one of the member functions. This feels like a pretty standard problem, but all of the solutions I find online are either simple bracket issues, or scope resolution stuff that seems really obvious, or massively complex examples that shroud what's actually going on in over-complexity. I really appreciate anyone that Might be able to help me understand what I'm doing wrong with these files.
The errors I get are
undefined reference to Test::Test()'
undefined reference to Test::msg()'
I have three files, a main, a Test.hpp, and Test.cpp.
main.cpp
#include "Test.hpp"
#include <iostream>
using namespace std;
int main(){
Test var;
var.msg();
return 0;
}
Test.hpp
#ifndef TEST_HPP
#define TEST_HPP
class Test{
public:
Test();
void msg();
};
#endif
Test.cpp
#include "Test.hpp"
#include <iostream>
using namespace std;
Test::Test(){
cout << "instantiated\n\n";
}
void Test::msg(){
cout << "Hello\n\n";
}
Considering you use codeblocks as your IDE just go to: project settings -> project build options -> search directories -> add and locate where your .cpp and .h files are. Then it will ask you if you want to keep this as relative path. Say no.
If you using some other ide its almost the same proccess, just comment me and i will provide you the steps.
Btw there is no need to include iostream in main since you have already included it in test.
This question already has answers here:
Using std Namespace
(16 answers)
Closed 7 years ago.
I have an existing project where the STL types are recognized. However, when creating a new project none of the STL types are not recognized. For example in
#include <string>
string s;
the colour of stringwill not change and compilation will generate errors.
Strangly enough when on the include line "Follow symbol under cursor" is executed the include file is opened. So the include file is there, Qt Creator knows how to open it and still class string is not recognized.
Did a reinstall of Qt5.5 but no avail.
What's happening?
you should use:
std::string
or:
using namespace std
at the beggining and you will not have to add the namespace every time
This question already has answers here:
vcl.h: No such file or directory
(2 answers)
Closed 8 years ago.
When trying to run this code on Xcode, #include vcl.h gets an error that says vcl.h file not found. Can someone help me fix it? The error occurs in the first line of the program code.
#include <vcl.h>
#pragma hdrstop
#include <stdio.h>
#include <stdlib.h>
#include <stdexcept>
//---------------------------------------------------------------------------
vcl.h is provided by Borland C++ Builder. It is not a standard library, so you need to provide it somehow.
It appears that the old C++ builder is now the Embarcadero C++ Builder, so you may need to install that library first
Instead of the angled brackets, have you tried a quoted import?
#include "vcl.h"
Do you actually have the header and associated file in your project? because I don't think vcl.h is a system library. All I can find about it is that it is a Borland specific file, which does not come with Xcode.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
error: ‘NULL’ was not declared in this scope
i'm having this code, which has been written in visual studio but i`m working in eclipse and i'm trying to make it compilable for eclipse and i throws me this error
..\heap.cpp:104:10: error: 'NULL' was not declared in this scope
code:
#include"heap.h"
using namespace std;
template<class T>
Heap<T>::Heap() // constructor
{
root = NULL;
size = 0;
}
Eclipse isn't a compiler, just an IDE. I'm guessing you're using it with another compiler than Visual Studio and the system headers are somewhat different, leading to your VC++ working includes to not include the declaration of NULL on <the other compiler>. As Martinho Fernandes said, you need to include <stdlib.h> or <cstdlib>, or some header that includes those ones. As the other question says, the C++ 11 way would be <stddef.h> or <cstddef>.