Thread: decontructing c++

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    3

    Question decontructing c++

    Hi,
    I'm trying to get into C++, but i tend to learn stuff better in my own strange way
    [using vc++ 6]
    i had a simple program that was like

    Code:
    #include <iostream.h>
    void main
    {
    char thisisyourname[30];
    cout << "What is your name?";
    cin >> thisisyourname;
    cout << endl << "Your name is " << thisisyourname;
    }
    if i've made an obvious mistakes it's cos i'm writing it from memory. (it did work)
    And then i wondered about iostream.h, couldnt I take some stuff out of there and write it in the program and do away with the #include
    and after looking at webpages from http://www.cplusplus.com/ref/iostream/ i came up with

    Code:
    // #include <iostream.h>
    void main()
    {
    char thisisyourname[30];
    istream::write "what is your name?";
    istream::getline (thisisyourname,30); 
    ostream::write "You are " && thisisyourname;
    
    
    }
    which has lots of errors like
    istream' : is not a class or namespace name
    and 'write' : undeclared identifier
    in fact one set for every line.
    i expect '&&' is wrong as well, i just guessed.

    question is. can this work? differently?

    cheers
    Last edited by browolf; 04-03-2003 at 05:16 AM.

  2. #2
    ! |-| /-\ +3 1337 Yawgmoth's Avatar
    Join Date
    Dec 2002
    Posts
    187
    What's with all the underscores?

    Code:
    #include <iostream.h>
    //May have to #include <iostream> depending on compiler
    using namespace std;
    
    int main()
    {
    char name[50];
    cout <<"What's your name?";
    cin>>name;
    cout << "\n"; //Could also be cout << endl;
    cout << "Your name is " << name;
    return 0; 
    }
    L33t sp3@k sux0rz (uZ it t@k3s 10 m1|\|ut3s 2 tr@nzl@te 1 \/\/0rd & th3n j00 h@\/3 2 g3t p@$t d@ m1zpelli|\|gz, @tr0(i0u$ gr@mm@r @|\|d 1n(0/\/\pr3#3|\|$1bl3 $l@|\|g. 1t p\/\/33nz j00!!

    Speling is my faverit sujekt

    I am a signature virus. Add me to your signature so that I may multiply.

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    3
    Originally posted by Yawgmoth
    [B] What's with all the underscores?
    dunno they just turned up. maybe cos i pasted the msg from another webpage. i've edited them out.
    Last edited by browolf; 04-03-2003 at 05:15 AM.

  4. #4
    Registered User
    Join Date
    Jan 2003
    Posts
    311
    In C++ you cannot just do away with the include. If you really wanted to, you could write the prototypes yourself, but iostreams is a complicated little beasty. In C a default prototype is assumed that "just happens" to match printf and scanf, or rather, the linker will do the right thing in it's confusion.

  5. #5
    The Pantless Man CheesyMoo's Avatar
    Join Date
    Jan 2003
    Posts
    262
    What's the point in not including headers?
    If you ever need a hug, just ask.

  6. #6
    Registered User
    Join Date
    Apr 2003
    Posts
    3
    i was just trying to get a closer look at how c/c++ works. but as you say it gets complicated so i'm stearing clear for the time being.
    maybe when i know more.

  7. #7
    jasondoucette.com JasonD's Avatar
    Join Date
    Mar 2003
    Posts
    278
    Originally posted by CheesyMoo
    What's the point in not including headers?
    browolf is on the right track to understanding what is going on. Since code in headers (and their corresponding source files) is just included into the program (a rather primitive way of implementing 'units'), then you should be able to create your program entirely in one file (I know that it is not exactly that easy, since certain variables just have file scope, which would be eliminated in this way, since you now only have one file). But, the point is, browolf, is that if you have a program this complicated, you should be using includes for your header files. When you have code structures in your program that can be used in other programs, they should be contained within their own .h/.cpp file pair as a 'unit', which can be included to multiple programs.

Popular pages Recent additions subscribe to a feed