Thread: c++ or c ?

  1. #1
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572

    c++ or c ?

    quick question, would this code be considered fully c++ or fully c? I've never learned c, but I believe that sscanf (c) is similar to cin (c++), but I'm not sure....

    Code:
    ifstream examplefile(argv[1]); //open a file indicated by the single command
                                       //line argument
        if (! examplefile.is_open())
        { 
           cout << "Error opening file"; exit (1);
        } 
        examplefile.getline (buffer,100);
        sscanf(buffer,"%d", &line);
        cout << line << endl;
        for (i=1; i<=line; i++)
        {
           examplefile.getline (buffer,100);
           sscanf(buffer, "%d, %d", &con1, &con2);
           cout << con1 << "," << con2 << endl;
        }
    thanks, axon

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    fullly C++, yes, because C++ encompasses (almost?) all of C. fully C, no, because C can never uses classes like ifstream or objects like cout.

  3. #3
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Technically full C++ as elad said. Practically, I'd call it a mix of the two, though.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  4. #4
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    In reality pure C++ is quite ugly. Most use a mixture of the two which is why we all love this C/C++ world.

  5. #5
    Registered User
    Join Date
    May 2003
    Posts
    1,619
    Originally posted by Bubba
    In reality pure C++ is quite ugly. Most use a mixture of the two which is why we all love this C/C++ world.
    I tend to disagree, I almost never include any of the c header files in any of my programming. Pure C++ can look quite elegant when properly written.

    I don't passionately avoid C, but I tend to use the newer ways to do things.
    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.

  6. #6
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    ^ you don't even use C-style strings?
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  7. #7
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    I usually try to steer clear of C. I like the STL containers and the string class more than C-style strings. I like cout and cin better than scanf and printf. I like new and delete better than malloc and free. I like every improvement over C, so I use those nice features of C++.
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  8. #8
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    well, I do have to say I use mostly C++, but that's because I never learned C... some C is helpful, but I don't think I'll go back and learn anytime soon because 1) every book i've read says not to, and 2) I'm going to learn different languages first...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  9. #9
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Well, one will probably have to use C-style strings somewhere

  10. #10
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    I think of null terminated char arrays, functions, arrays, loops, etc as being essential to both C and C++. The differences in I/O routines, memory management, and underlying mechanisms to model reality delineate what I think of as C vs C++. I tend to think of STL (with the string class, list class, vector class, algorithms, etc) as another non-proprietary layer of complexity wherein standards have been agreed upon so we don't have to each keep inventing our own wheel; whereas MFC, VCL and other libraries are propietary standards that may or may not be routinely available and/or standardized, but still offer prebuilt routines to make our lives easier.

Popular pages Recent additions subscribe to a feed