im extreamly new help

This is a discussion on im extreamly new help within the C++ Programming forums, part of the General Programming Boards category; THX a lot i got it to work like this Code: #include <iostream.h> using namespace std; int main() { int ...

  1. #16
    Registered User
    Join Date
    Apr 2004
    Posts
    12
    THX a lot i got it to work like this

    Code:
    #include <iostream.h>
    using namespace std;    		
    int main()	      	
     { 
      int x;                
      for(int x=0;x<2;x++) 
      {			     
        cout<<    "Hello it's me Mario" <<endl;          
     } 
      return 0;  
    }

  2. #17
    Registered User
    Join Date
    Apr 2004
    Posts
    21
    The first int x is not needed. It is declared in the FOR loop.

  3. #18
    Registered User
    Join Date
    Apr 2004
    Posts
    12
    o really.....thx
    didnt know

  4. #19
    Registered User
    Join Date
    Jan 2003
    Posts
    648
    You're still using iostream.h. Use the new one without the .h. And format your code cleanly:
    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
      for(int x = 0; x < 2; x++)
      {
        cout << "Hello it's me Mario" << endl;
      }
      return 0;
    }
    You can also use this brace style:
    Code:
    #include <iostream>
    using namespace std;
    
    int main() {
      for(int x = 0; x < 2; x++) {
        cout << "Hello it's me Mario" << endl;
      }
      return 0;
    }

  5. #20
    Registered User
    Join Date
    Apr 2004
    Posts
    12
    k i will
    i like the first brace style better

  6. #21
    Registered User
    Join Date
    Apr 2004
    Posts
    12
    like u said i should use iostream not iostream.h
    goes same way for conio.h? should i use conio alone?

  7. #22
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    yeah, for pretty much every header file, there's a version without the .h at the end... if it's an C header file, the syntax is <c*> instead of <*.h>and if it's a c++ header the syntax is <*> instead of <*.h>... hope you got that...

    speedy5's second brace style is ugly, although alot of people seem to like using it... another way you could do it is like this:
    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
       for(int x = 0; x < 2; x++)
          cout << "Hello it's me Mario" << endl;
       return 0;
    }
    in that case, only the line after the loop will be looped... you could also do it like this:

    Code:
    int main()
    {
       for(int x = 0; x < 2; x++)   cout << "Hello it's me Mario" << endl;
       return 0;
    }
    but that's evil as well...
    Last edited by major_small; 04-23-2004 at 09:58 PM. Reason: missed a code tag...
    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

  8. #23
    Registered User
    Join Date
    Jan 2003
    Posts
    648
    Watch out, its not the line after: its the first statement after. A statement ends with a semicolon. A block (curly braces) can be regarded as one statement.

  9. #24
    Registered User
    Join Date
    Mar 2004
    Posts
    494
    read thru the FAQS, tutorials and quizes man, ull see that a lot of ur questions will b answered not in much detail but in a way u can understand it, this is the best way to learn, if u ask questions for every little thing u wont learn anything lol. i also suggest u get a book too. its not as simple as u think, u need to really understand it to get it ehehe
    When no one helps you out. Call google();

  10. #25
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    Quote Originally Posted by Speedy5
    Watch out, its not the line after: its the first statement after. A statement ends with a semicolon. A block (curly braces) can be regarded as one statement.
    I know that, it's just easier to tell them that for now and then give them more insight into it later on... IMO, it's best to get the basics down and then build on that instead of throwing lots of info at them... for example, tell somebody how to use fstream, and when you get to classes and OOP, show how it follows the syntax of a class...
    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

  11. #26
    Registered User
    Join Date
    Jan 2003
    Posts
    648
    I don't find that learning methodology easier. Learning the language's fundamentals first such as syntax is better since then you can apply it to every library and utility. Just take math for example. With just a few basic algebraic identities, you can solve many of the larger, complex problems.

    Learning that a statement is either a block of curly braces or a semicolon will avoid many errors. What if he wants to put two statements? Under your way, both should execute since they're on the same line.

    The "mathematical" way is better. Take language constructs for example. Its easy to understand once you define what a statement is and what an expression is (a non-block statement that evaluates to something without a semicolon).
    Code:
    if (<expression>)
      <statement>
    
    for (<init expression>; <conditional expression>; <step expression)
       <statement>
    
    while (<expression>)
       <statement>
    
    ...
    I know when I learnt Java as a 5th grader (my first language), I learnt how to use OOP first without doing anything fancy. Then it was cake applying what I learnt about classes into learning about the standard libraries. It was just what I learnt in a bigger scale. I was able to use and apply every package within minutes without learning any new syntax.
    Last edited by Speedy5; 04-23-2004 at 10:38 PM.

  12. #27
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    your way definately has an advantage, but doing it my way, I would at first imply that each statement has to be on it's own line... hence part of my reason for calling my second example 'evil'... I'm talking about more of learning C++ as a first language... it's also just from experience... when I found out how classes worked and got a good understanding of exactly what OOP meant, I felt so much more comfortable with it because I could then apply a deeper understanding to what I already knew how to use...
    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

  13. #28
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,088
    Quote Originally Posted by rigo305
    like u said i should use iostream not iostream.h
    goes same way for conio.h? should i use conio alone?
    No, conio.h is not part of the standard libraries. Only the standard libraries have been updated to remove the '.h'. The FAQs and the search utility are two great ways to find out about these things (you'll actually learn more than by just asking questions here). Unfortunately, I don't think there is a good FAQ on this site about which library headers to use and why (there should be one, it is asked frequently). Here is a mini FAQ answer:



    Before the most recent C++ standard, most compilers provided libraries like iostream.h, fstream.h and iomanip.h with the '.h' extension. When the standard became standard, they decided to put all the stuff in those header files into the std namespace, and the new headers that follow the standard don't have the '.h' extension.

    Also, the standard C library has the headers like stdio.h, stdlib.h, math.h and time.h. With the new C++ standard, those header files were deprecated (they are still allowed for now, but might not be supported in the future). Instead, the new header files were created without the '.h' and with an extra 'c' at the beginning, like cstdio, cstdlib, cmath and ctime.

    So, in general, you should use the ones without the .h, because they are the standard headers.

    Here are the headers that my standard library implementation has. When there are two possible headers to use, I put the ones you should use in blue and the ones you should avoid in red. The ones in black are new to the C++ standard and are of course good to use also.

    The Standard C++ library consists of 51 required headers. This implementation also includes three additional headers, <hash_map>, <hash_set>, and <slist>, not required by the C++ Standard, for a total of 54 headers. Of these 54 headers, 16 constitute the Standard Template Library, or STL. These are indicated below with the notation (STL):

    <algorithm> -- (STL) for defining numerous templates that implement useful algorithms
    <bitset> -- for defining a template class that administers sets of bits
    <complex> -- for defining a template class that supports complex arithmetic
    <deque> -- (STL) for defining a template class that implements a deque container
    <exception> -- for defining several functions that control exception handling
    <fstream> -- for defining several iostreams template classes that manipulate exteral files
    <functional> -- (STL) for defining several templates that help construct predicates for the templates defined in <algorithm> and <numeric>
    <map> -- (STL) for defining template classes that implement hashed associative containers that map keys to values
    <hash_set> -- (STL) for defining template classes that implement hashed associative containers
    <iomanip> -- for declaring several iostreams manipulators that take an argument
    <ios> -- for defining the template class that serves as the base for many iostreams classes
    <iosfwd> -- for declaring several iostreams template classes before they are necessarily defined
    <iostream> -- for declaring the iostreams objects that manipulate the standard streams
    <istream> -- for defining the template class that performs extractions
    <iterator> -- (STL) for defining several templates that help define and manipulate iterators
    <limits> -- for testing numeric type properties
    <list> -- (STL) for defining a template class that implements a doubly linked list container
    <locale> -- for defining several classes and templates that control locale-specific behavior, as in the iostreams classes
    <map> -- (STL) for defining template classes that implement associative containers that map keys to values
    <memory> -- (STL) for defining several templates that allocate and free storage for various container classes
    <new> -- for declaring several functions that allocate and free storage
    <numeric> -- (STL) for defining several templates that implement useful numeric functions
    <ostream> -- for defining the template class that performs insertions
    <queue> -- (STL) for defining a template class that implements a queue container
    <set> -- (STL) for defining template classes that implement associative containers
    <slist> -- (STL) for defining a template class that implements a singly linked list container
    <sstream> -- for defining several iostreams template classes that manipulate string containers
    <stack> -- (STL) for defining a template class that implements a stack container
    <stdexcept> -- for defining several classes useful for reporting exceptions
    <streambuf> -- for defining template classes that buffer iostreams operations
    <string> -- for defining a template class that implements a string container
    <strstream> -- for defining several iostreams classes that manipulate in-memory character sequences
    <typeinfo> -- for defining class type_info, the result of the typeid operator
    <utility> -- (STL) for defining several templates of general utility
    <valarray> -- for defining several classes and template classes that support value-oriented arrays
    <vector> -- (STL) for defining a template class that implements a vector container

    The Standard C++ library works in conjunction with the 18 headers from the Standard C library, sometimes with small alterations. The headers come in two forms, new and traditional. The new-form headers are:

    <cassert> -- for enforcing assertions when functions execute
    <cctype> -- for classifying characters
    <cerrno> -- for testing error codes reported by library functions
    <cfloat> -- for testing floating-point type properties
    <ciso646> -- for programming in ISO 646 variant character sets
    <climits> -- for testing integer type properties
    <clocale> -- for adapting to different cultural conventions
    <cmath> -- for computing common mathematical functions
    <csetjmp> -- for executing nonlocal goto statements
    <csignal> -- for controlling various exceptional conditions
    <cstdarg> -- for accessing a varying number of arguments
    <cstddef> -- for defining several useful types and macros
    <cstdio> -- for performing input and output
    <cstdlib> -- for performing a variety of operations
    <cstring> -- for manipulating several kinds of strings
    <ctime> -- for converting between various time and date formats
    <cwchar> -- for manipulating wide streams and several kinds of strings
    <cwctype> -- for classifying wide characters

    The traditional Standard C library headers are:

    <assert.h> -- for enforcing assertions when functions execute
    <ctype.h> -- for classifying characters
    <errno.h> -- for testing error codes reported by library functions
    <float.h> -- for testing floating-point type properties
    <iso646.h> -- for programming in ISO 646 variant character sets
    <limits.h> -- for testing integer type properties
    <locale.h> -- for adapting to different cultural conventions
    <math.h> -- for computing common mathematical functions
    <setjmp.h> -- for executing nonlocal goto statements
    <signal.h> -- for controlling various exceptional conditions
    <stdarg.h> -- for accessing a varying number of arguments
    <stddef.h> -- for defining several useful types and macros
    <stdio.h> -- for performing input and output
    <stdlib.h> -- for performing a variety of operations
    <string.h> -- for manipulating several kinds of strings
    <time.h> -- for converting between various time and date formats
    <wchar.h> -- for manipulating wide streams and several kinds of strings
    <wctype.h> -- for classifying wide characters

    Finally, in this implementation, the Standard C++ library also includes several headers for compatibility with traditional C++ libraries:

    <fstream.h> -- for defining several iostreams template classes that manipulate exteral files
    <iomanip.h> -- for declaring several iostreams manipulators that take an argument
    <iostream.h> -- for declaring the iostreams objects that manipulate the standard streams
    <new.h> -- for declaring several functions that allocate and free storage
    <stl.h> -- for declaring several template classes that aid migration from older versions of the Standard Template Library

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

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