开发者

C++ header confusion

开发者 https://www.devze.com 2023-03-02 11:35 出处:网络
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

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.开发者_JAVA百科 I can't seem to make sense out of the MinGW documentation.


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...


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消