Thread: Simple C++ question

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    4

    Simple C++ question

    I'm in my first class for C++. Can someone please tell me how to declare a string "consumer"?


    Thanks in advance

  2. #2
    root
    Join Date
    Sep 2003
    Posts
    232
    Code:
    #include <string>
    
    std::string consumer;
    Or since this is a class and you probably aren't supposed to use the string class:
    Code:
    char consumer[100];
    100 is an arbitrary size, change it to suit your needs.
    The information given in this message is known to work on FreeBSD 4.8 STABLE.
    *The above statement is false if I was too lazy to test it.*
    Please take note that I am not a technical writer, nor do I care to become one.
    If someone finds a mistake, gleaming error or typo, do me a favor...bite me.
    Don't assume that I'm ever entirely serious or entirely joking.

  3. #3
    Registered User
    Join Date
    Oct 2003
    Posts
    4
    If I were to have #include main() can I also have #include <string> in the same code?

    Thanks for your response.

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    you're not supposed to #include main().

    anyways, yes, you can include more than one header file, and if your program calls for more then one, than you should.

  5. #5
    Registered User
    Join Date
    Oct 2003
    Posts
    4
    I'm confused! Can you please explain to me why I'm not supposed to use #include main()? Because, this is what my professor is teaching us.

  6. #6
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Your professor is an ignoramus (yes, you can tell him I said that). My advice would be to quit school, buy some good C++ books, and teach yourself!

    Anyway, you #include files, not functions - perhaps he meant "main.h" (assuming the file exists in your program workspace)?
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  7. #7
    Amateur
    Join Date
    Sep 2003
    Posts
    228
    #include main() won't even compile, I don't know how you can be taught such abominations anyway. If it is your first class, I won't be a good teacher, so, I'll just let others explain why it is so.
    But this post will be aimless if I didn't do something for you, so, here is a basic explanation.
    Code:
    // Consider a simple program that does nothing.
    // Here's the code.
    
    int main()
    {
        return 0;
    }
    For now, you don't need to know what int main() is, all you have to keep in mind is that everything inside of the brackets is your code and will be executed.
    See? there's no #include main() thing. #include is designed to include a file into the one which use the directive. For instance, if your file, named "main.cpp" uses #include <stdio.h>, the file named "stdio.h" will be copied into the "main.cpp" when it is loaded into memory to be compiled.
    The content of the file is not of import to you right now, just understand that it is here for you to use functions and classes (don't worry if you don't know what it is at present) that weren't available otherwise.

  8. #8
    Registered User
    Join Date
    Oct 2003
    Posts
    4
    OMG..I'm sorry guys! I'm the ignoramus! lol..

    Lack of sleep is a mofo. LMAO

    I hope my post here isn't a reflection of what my grade is going to be in this class.

    #include <iostream.h>
    #include <string>

    int main()

    Jeez I'm a goof! Ok so a revised question here.. You can use as many #include as you see fit..correct?

  9. #9
    Registered User
    Join Date
    Sep 2003
    Posts
    8
    Yes

  10. #10
    Registered User
    Join Date
    Oct 2003
    Posts
    13
    Originally posted by Newbie Magic
    Yes
    Umm... Not realy... Header files are there for a purpose. Such as std, a standered namespace, won't work without iostream. Putting to many will just increase file size and make you look noobish...

  11. #11
    root
    Join Date
    Sep 2003
    Posts
    232
    >Umm... Not realy...
    Why? If you need 10 functions from 10 different headers, you have little choice but to include all of those headers. Not doing so would give unpredictable behavior and make you look noobish.
    The information given in this message is known to work on FreeBSD 4.8 STABLE.
    *The above statement is false if I was too lazy to test it.*
    Please take note that I am not a technical writer, nor do I care to become one.
    If someone finds a mistake, gleaming error or typo, do me a favor...bite me.
    Don't assume that I'm ever entirely serious or entirely joking.

  12. #12
    Registered User
    Join Date
    Oct 2003
    Posts
    13
    Originally posted by twm
    >Umm... Not realy...
    Why? If you need 10 functions from 10 different headers, you have little choice but to include all of those headers. Not doing so would give unpredictable behavior and make you look noobish.
    Oh, I thought he ment just put them there for like no reason, my bad

  13. #13
    Registered User
    Join Date
    May 2003
    Posts
    1,619
    Originally posted by §tudent
    OMG..I'm sorry guys! I'm the ignoramus! lol..

    Lack of sleep is a mofo. LMAO

    I hope my post here isn't a reflection of what my grade is going to be in this class.

    #include <iostream.h>
    #include <string>

    int main()

    Jeez I'm a goof! Ok so a revised question here.. You can use as many #include as you see fit..correct?
    If your professor is honestly teaching to #include <iostream.h>, you should drop the class. That hasn't been legal C++ code for 5 years now.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

  14. #14
    Registered User
    Join Date
    Aug 2003
    Posts
    42
    I still use .h.

    Only because when I use
    Code:
    using namespace std;
    It says there is no namespace std.

    O_o
    Sigh, nothing ever works the first try.

    Register Linux User #314127

  15. #15
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    Originally posted by KneeLess
    I still use .h.

    Only because when I use
    Code:
    using namespace std;
    It says there is no namespace std.

    O_o
    get a newer compiler.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple question regarding variables
    By Flakster in forum C++ Programming
    Replies: 10
    Last Post: 05-18-2005, 08:10 PM
  2. Simple class question
    By 99atlantic in forum C++ Programming
    Replies: 6
    Last Post: 04-20-2005, 11:41 PM
  3. Simple question about pausing program
    By Noid in forum C Programming
    Replies: 14
    Last Post: 04-02-2005, 09:46 AM
  4. simple question.
    By InvariantLoop in forum Windows Programming
    Replies: 4
    Last Post: 01-31-2005, 12:15 PM
  5. simple fgets question
    By theweirdo in forum C Programming
    Replies: 7
    Last Post: 01-27-2002, 06:58 PM