compiler

Hi, I changed books from Jumping into C++ using code-block as my compiler and #include <iostream> to "Programming: Principles and Practice using C++"
got the suggested compiler and used the tutorial to add the std_lib_facilities.h file. The header file contained in the compiler seemed to be empty, it wouldn't allow me to open it, I pasted the std file into it. I reloaded it.....well let's just say it took a week and my needing to restore my system several times. The compiler would not run, didn't recognize the Header file inclusion even after using the "#include .../.../.../std_lib_facilities.h that the book said I needed to get it into my program.
My problem is I can't do the exercises in the book on either compiler and using #include <iostream> doesn't work. I can't use code that is included in that header file, im stuck!! I need a compiler that will work with the std_lib_facilities in it's header file. The one that the book suggested and uses had been updated and only a trial now but the book is like 10 years old. HELP Please!!

I dont really understand but I use Dev-C++ IDE since my first tme learn c++, maybe you can try it ?
That header file and all of the non-standard ones he uses are not part of any compiler. You need to download them from his site:http://www.stroustrup.com/Programming/
and import them intoto your project. I believe the download you want is called Complete collection of code fragments for the 1st edition (revised) near the middle of the page. That particular one changes, if I remember right, as the progresses so you have to use the one for the right chapter also.

btw, the reason you do not have to include iostream is because it is already included in that header file along with several of the functions he uses.
Yeah that's the compiler that I just couldn't get to accept code or the header file suggested by the book. I followed all the steps to the letter. I went and got Dev-c++IDE as LendraDwi suggested and though I can't use the Include statement in the book the code is working in that program. It is using two include statements already set up. Will I be able to use this book with the compiler I just got now? I would hate to get more into this book and find I can't practice the sessions because of the darned compiler. This is all so confusing, I thought a computer language was a set pattern of a set series of code. How and what am I supposed to learn if it keeps changing?
For the sake of simplicity, I will not get into the differences between a compiler and an IDE. If you do not download the header files from his site and add them to your project, no compiler or IDE will work with the code given in that book. If you do download and add the header files almost anything will work. I can assure you that both C::B and VS both have no problems if those two simple things.

If you are having trouble adding the header files to your project, that is a different story and you need to say that instead of complaining about IDEs.
I use Dev-C++ IDE as well and it has been working good for me as a beginner. I am still learning about this but Give it a try it might work for you.
admkrk I sure didn't mean to complain, i'm totally new to all this. Zero knowledge of programming or compilers. I was studying in" Jumping into C++" but there weren't a lot of practice sessions, someone here suggested I get "programming principles and practices using C++", which I also had and is a much more in depth book but it called for a different compiler, I got that complier and the header file, seemed to have been successful in pasting it into the program ( using a tutorial) but couldn't get it to work no matter what I did, so, I was asking for options and asking if this new complier would still work with the book.
Code-Block wouldn't accept code like "string first_name = "???" or int age =-1 in the main function. That was my confusion, the code in main itself, is that not uniform through out C++? or does the actual code differ from compiler to compiler? P>S so far this new compiler is working with the code in the book but then again i'm only in chapter 3.
Since there are a couple of mentions of DevC++ in this thread, it's probably worth adding a reminder that it is the Orwell version which should be used. (The original one hasn't been updated since 2005 and is considered obsolete).

http://orwelldevcpp.blogspot.com/

To tell the IDE where to look for your include (header) files:

In Orwell DevC++ try this. From the main menu, select tools->compiler options
A window should be displayed with further options. Select the "Directories" tab, then the "C++ Includes" tab. At the bottom-right of the panel, is an icon to click in order to browse to the directory where your header files are located. In my case it was F:\temp, click add and ok then try to compile your program. it should now be able to find the files and build / run your program.

Last edited on
Hi DianaV, which IDE or compiler you use does not matter. Some have a different way of doing things, but they should all work. To add to what Chervil said, for C::B put the header in the same folder as your .cpp and right click the project name > add files..., in the pop-up select the header and click Open. It will then be added to your project and you can then include it. VS is almost the same except after the right click its > add... > add existing item....

If you are getting errors writing
1
2
string first_name = "???";
int age = -1;

then there is something else wrong going on and without specifics it is impossible to guess what that might be.
The only error I would venture to guess you are getting from that code would be similar to one of these:

file.cpp: In function ‘int main()’:
file.cpp:5:2: error: ‘string’ was not declared in this scope
  string first_name = "???";
  ^
filecpp:5:2: note: suggested alternative:
In file included from /usr/include/c++/4.8/string:39:0,
                 from DianaV2.cpp:1:
/usr/include/c++/4.8/bits/stringfwd.h:62:33: note:   ‘std::string’
   typedef basic_string<char>    string;
                                 ^
file.cpp:5:9: error: expected ‘;’ before ‘first_name’
  string first_name = "???";
         ^
file.cpp:6:6: warning: unused variable ‘age’ [-Wunused-variable]
  int age = -1;
      ^
Compilation failed.

As I said before, each chapter has a different std_lib_facilities.h, the one for chapter 3 starts out with:
1
2
3
4
5
6
7
8
#include <algorithm>
#include <cmath>
#include <iostream>
#include <stdexcept>
#include <string>
#include <vector>

using namespace std;


The one for chapter 2 starts with only:
1
2
3
#include <iostream>

using namespace std;


So yes, not including string and/or missing semicolons would be the first places to look. If the correct header is included, all the includes should be there though. It is easy enough to just add them to the .cpp, but functions like keep_window_open() will also cause errors without the header.
All those errors come from simply not including std:: in front of string in my definition of first_name. Then of course not using age.
Last edited on
OH crap! I didn't include all those "include" statements just the (iostream) one, in Code Blocks, the compiler didn't even give me an error message...just sorta laid there....lol wouldn't even try and compile my program. So it sounds like I still need to add this header file I will try to get it into Code Block and this other one I like them both, they seem easier to use then the recommended one in the book. Thank all of you for your help...I will give it a whirl. :)
oh one more thing....can I just add all those header files to my programs each time, I wouldn't know when to add them or when not to at this point. Do you have to use each (include) for the program to compile and run?
You could add the includes to the .cpp instead of including the header, but like I said each chapter is different and you would need to add the functions as well. It is much simpler to just import the header into your project and be done with it though. Just copy it to the same place your .cpp is and use add file to import it into your project. You will know it is imported properly when it shows up in the headers folder of the project view.

From C::B Wiki: http://wiki.codeblocks.org/index.php?title=Creating_a_new_project#Adding_a_pre-existing_file
Just follow along as if you had created the header yourself.
Topic archived. No new replies allowed.