0

So in the down time before summer semester, I'm trying to learn a little C++ on my own. I'm working through a book, but not using the compiler provided. Instead, I'm using MinGW. The problem I've encountered is that the headers the two compilers need appear to be somewhat different. For example, where the text uses

#include <iostream.h>

...the MinGW C++ compiler needs...

#include <iostream>

... so now I have a simple program manipulating strings I'm trying to run, and the header provided in the text is...

#include <string6.h>

...and I don't know what header to include to make it run. In fact, I don't really know how headers work. I have a cursory knowledge of Java and Python and that's it. Do I need to install the compiler that came with the text after all? Where can I find a list of the headers used by the MinGW C++ compiler for different data? Here is the code I was trying to run...

int main() {
    string s1;
    string s2;

    s1 = "This is a test";
    s2 = "and so is this.";

    cout << s1;
    cout << s2;

    return 0;
}

Any help and insight into the general way headers work would be much appreciated. I can't seem to make sense out of the MinGW documentation.

  • What version of C++ does this text use? If you wish to make life easy for yourself with the book then why can't you just use the compiler that is supplied with it? – David Heffernan May 04 '11 at 04:35
  • Which book are you actually using? Could `` be a header defined by the book, perhaps in an appendix? It isn't a standard C++ header. – Jonathan Leffler May 04 '11 at 04:51
  • 1
    Any book using iostream.h should not be read in 2011. [We have a list of good books](http://tinyurl.com/so-cxxbooks); look at [PPPuC](http://tinyurl.com/pppuc) especially. – Fred Nurk May 04 '11 at 05:35
  • `` has been deprecated for more than a decade. You've found a terrible book – jalf May 04 '11 at 06:59

2 Answers2

5

Get yourself a newer book - see The Definitive C++ Book Guide and List for suggestions.

The <iostream.h> notation headers were used before the C++ standard was published - which was in 1998. The standard dropped the .h suffix.

It also added lots of features that your book probably doesn't cover - notably the template library.

If you must use your book, drop the .h suffix from most headers. Where the header is also used by C, though, you would either continue to use the .h suffix (e.g. <stdio.h>), or prefix the name with c, as in <cstdio>. But expect some problems...

Community
  • 1
  • 1
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
  • It's definitely an old book. I think I'm going to take david's advice and just use the provided compiler. Do you think it will adversely affect my learning to begin on pre-standard material and move up to newer things when I have the money for a new book? I'm a student, and I got this book cheap (now you know why haha). I don't exactly have money for new one's lying around at the moment. –  May 04 '11 at 04:51
  • 2
    @Masstrike - Yes, if the book is actually older than 1998, it is just ancient. :-) The way we use the language has changed **a lot** since then. – Bo Persson May 04 '11 at 04:57
  • @MassStrike: I think you'd be better off learning C++ from one of the modern C++ books than from a really old one. Things have changed dramatically. For example, you probably shouldn't bother with learning about arrays - learn about the `std::vector<>` template class instead, and use it. For a far more authoritative voice than mine on the subject, see Andrew Koenig's blog at Dr Dobbs on [Teaching C++ Badly: How to Misuse Arrays](http://drdobbs.com/blogs/cpp/229401975). That's but the tip of an awfully big iceberg. – Jonathan Leffler May 04 '11 at 04:59
  • There're a lot of free book about C++, try Thinking in C++. – Kien Truong May 04 '11 at 05:01
  • Ok, thanks for the info guys. I suppose I'm in the market for a new C++ book, then haha....Any suggestions? I'm not really a fan of online or downloadable material for something which I'm going to be reading five pages or more of at a time. I much prefer a physical book. –  May 04 '11 at 05:08
  • @MassStrike: I don't think you'd go far wrong with any of the 4 books listed in the 'Beginner: Introductory' section of the Definitive C++ Book Guide and List referenced in my answer. The 'C++ Primer' is a big book (even printed on bible-paper thin pages); I'd probably go with 'Accelerated C++' or 'Programming: Principles and Practice Using C++', but the choice is yours. – Jonathan Leffler May 04 '11 at 05:44
-1

You better read the MinGW documentation and samples. String manipulation can be a bit different from one compiler to other.

You can also install visual studio express, it's free.

ariel
  • 15,620
  • 12
  • 61
  • 73
  • While VS is nice and all, I think this can be solved without changing tools. Checking the docs and/or standard is a good idea. – ssube May 04 '11 at 04:40