Newbie with Very Newbie Question

This is a discussion on Newbie with Very Newbie Question within the C++ Programming forums, part of the General Programming Boards category; #include <string> std::string input;...

  1. #16
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,918
    #include <string>
    std::string input;
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #17
    Registered User
    Join Date
    Jan 2005
    Posts
    7,344
    >> Now, are you saying that I type in #include <string> literally, instead of replacing that "<string>" with a file or directory name?

    Yes. Currently, in your Hello World.h header, you "use the <iostream> "dictionary" of commands". That's what you need to do with <string> as well.

    Your understanding of headers and namespaces could probably use a refresher, perhaps find that section of your book/tutorial and re-read it. A #include basically copies the contents of a header file into that spot in the program. Standard headers are placed in <> brackets and do not end in .h even though they are all implemented as files. Your own headers are usually placed in "" quotes.

    You almost never #include anything other than .h or .hpp files or files with no extension from the standard library. The .txt file you have included there looks suspicious, why are you #includ'ing it?

    Normally, based on the code you are using, the top of your file would look like this:
    Code:
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    int main()
    {

  3. #18
    Registered User
    Join Date
    Jun 2008
    Posts
    11
    Yes, that .txt was my erroneous attempt to link an #include to a file that was supposed to serve as one of those .str files I was talking about. But I didn't know if C++ saved in .str, so I hoped that .txt would work just as fine. It turns out, of course, that I didn't need it, since you helped me to solved my problem.

  4. #19
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,918
    #include will copy and paste whatever contents if whatever file you specify.
    Of course, you can't just paste some nonsensical data and expect it to work.
    It was designed to include headers with declarations and definitions.
    The extension doesn't matter. You can put valid contents in a .txt file and include it if you wish, but it will raise some eyebrowns from some people.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stupid Newbie question
    By TimL in forum C++ Programming
    Replies: 4
    Last Post: 07-22-2008, 05:43 AM
  2. C prog newbie question
    By Draginzuzu in forum C Programming
    Replies: 1
    Last Post: 02-03-2003, 06:45 PM
  3. a stupid question from a newbie
    By newcomer in forum C++ Programming
    Replies: 4
    Last Post: 01-11-2003, 04:38 PM
  4. confusion with integers (newbie question)
    By imortal in forum C Programming
    Replies: 7
    Last Post: 12-06-2002, 04:09 PM
  5. newbie class templates question
    By daysleeper in forum C++ Programming
    Replies: 2
    Last Post: 09-18-2001, 10:50 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21