noob in need of master

This is a discussion on noob in need of master within the C++ Programming forums, part of the General Programming Boards category; Looks like Mathfan and Dae have everything covered here, but I'd just like to correct a typo: >>which is parsed ...

  1. #31
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Looks like Mathfan and Dae have everything covered here, but I'd just like to correct a typo:
    >>which is parsed to the readsome() function.

    The bolded word should be 'passed'. Just didn't want it confusing gothpunk any more than it already is
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  2. #32
    Registered User MathFan's Avatar
    Join Date
    Apr 2002
    Posts
    190
    Quote Originally Posted by Hunter2
    >>which is parsed to the readsome() function.

    The bolded word should be 'passed'.
    Oops... Sorry, my bad
    The OS requirements were Windows Vista Ultimate or better, so we used Linux.

  3. #33
    Registered User
    Join Date
    Jun 2005
    Posts
    15
    This is one of the most helpful forum boards there is!


    anyways when you use fstream, does it have to be:
    Code:
    ofstream a_file ( "example.txt", ios::app );
    or can it be:
    Code:
    ofstream txt ( "example.txt", ios::app );
    ????


    also if this is to hard for a noob then can you think of a proggy that would be more suitable to learn off of?

  4. #34
    Registered User MathFan's Avatar
    Join Date
    Apr 2002
    Posts
    190
    Quote Originally Posted by gothpunk
    anyways when you use fstream, does it have to be:
    Code:
    ofstream a_file ( "example.txt", ios::app );
    or can it be:
    Code:
    ofstream txt ( "example.txt", ios::app );
    ????
    Totally up to you. You can name the variable whatever you want (there are some rules though, like you can't have numbers as the first characters of the name, there shouldn't be spaces etc.). Like:
    Code:
    //correct
    ofstream ThisIsCoolVar;
    ofstream This_is_cool_var;
    ofstream thisiscoolvar3;
    
    //incorrect
    ofstream 3var;
    ofstream this is a var;
    also if this is to hard for a noob then can you think of a proggy that would be more suitable to learn off of?
    May be some really basic tutorial will help?

    Are you sure you've seen this page? Begin at the top with the first tutorial....

    A tutorial here too.

    There are really many tutorials you can use. You can try to google "c++ tutorial" or something. There are really many such tutorials.

    Or may be you should buy a book?
    The OS requirements were Windows Vista Ultimate or better, so we used Linux.

  5. #35
    Registered User
    Join Date
    Jun 2005
    Posts
    15
    I am reading this tutorial, about.com's tutorial and have read jesse liberty's teach yourself c++ in 24 hours. they all have one problem, they don't/can't ansear questions.
    for example:
    Code:
    using namespace std;
    what is it where does it come from, how do I use/abuse it?
    also is this what I would use to declare:
    Code:
    std::system("date /t > example.txt");
    std::system("time /t >> example.txt");
    by using something like:
    Code:
    using system_time std;
    ?????

  6. #36
    Registered User MathFan's Avatar
    Join Date
    Apr 2002
    Posts
    190
    using namespace std;

    what is it where does it come from, how do I use/abuse it?
    It has something to do with namespaces. You will learn about them later. If you want to know now, look here.

    also is this what I would use to declare:
    Code:

    std::system("date /t > example.txt");
    std::system("time /t >> example.txt");


    by using something like:
    Code:

    using system_time std;
    No. Why are you trying to use the system() function again? Wasn't time() function I showed you fine? It is much better to use it than to use system().

    Though if you MUST use it (though you don't), do it like this:

    Code:
    #include <stdlib.h>
    
    int main()
    {
    	system("whatever");
    	return 0;
    }
    The OS requirements were Windows Vista Ultimate or better, so we used Linux.

  7. #37
    Dae
    Dae is offline
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Quote Originally Posted by gothpunk
    I am reading this tutorial, about.com's tutorial and have read jesse liberty's teach yourself c++ in 24 hours. they all have one problem, they don't/can't ansear questions.
    for example:
    Code:
    using namespace std;
    what is it where does it come from, how do I use/abuse it?
    also is this what I would use to declare:
    Code:
    std::system("date /t > example.txt");
    std::system("time /t >> example.txt");
    by using something like:
    Code:
    using system_time std;
    ?????
    Alright see.. You need to use google.com and search for a variety of tutorials so you can fully understand each aspect, since not every tutorial goes that full into detail on each subject.

    I saw about.com's explanation, its quite small. 'using namespace std;' is: declaring that you want to use everything declared in the namespace labeled STD in the file <iostream>. cout is labeled STD, cin is labeled STD, endl is labeled STD. If you did not declare 'using namespace std;' you would instead have to put 'std::' in front of everything in that namespace, therefor if you didnt declare that you would have to put: std::cout, std::cin, std::endl.

    So now from your "system" code.. by 'std::system("time /t >> example.txt");', you are saying you want to use the system function from the namespace std in the file <iostream> (which btw I dont think exists), therefor you would not need to use 'using namespace std;', but if you did you would only need 'system("time /t >> example.txt");'.. you see?

    By now you should see that 'using system_time std;' would be incorrect, even if there was a namespace called 'system_time' it would replace std, not namespace. ('using namespace system_time;')

    You can also declare 'using namespace std::cout;' or cin or endl, etc. The basic idea of all of the namespaces is std is standard, but if they had a modified version of cout, cin, endl, etc. then they could make a namespace for it and they wouldnt have to change the variable names or anything. A namespace is sort of like a class (or struct) in that way, that doesnt require an object of it.

    I hope some of that helps.. maybe you should try this sites tutorial first because I dunno about.com's one doesn rub me as the best starter.
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  8. #38
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    In C++, some variables are put into a group, and the group is given a name. For instance:

    std::cout
    std::cin

    'cout' is the name of a variable that handles output to the console window. 'cin' is the name of a variable that handles input from the console window. The name of the group they are in is called 'std'. In C++, if a variable is a member of a group, then you have to precede the variable name by the group name. So, you have to do this:

    std::cout<<"hello world"<<std::endl;

    However, if you put the following statement at the top of your file:

    using namespace std;

    then you don't have to precede the variable name by the group name for any of the variables in the 'std' group. Instead you can write,

    cout<<"hello world"<<endl;

    You might wonder what's the point of putting variables in a group. Imagine a team of 100 programmers working on the same program. The program they are working on might deal with apples, oranges, and bananas. What do you think the odds are that some of those programmers will name their variables the same names? Probably pretty high, and if two programmers use the same name for a variable, then it will cause errors when the code is combined into one single program. So, the team manager can assign each programmer a unique group name. Then, each programmer can add their variables to the group name they are assigned. The result is that if two programmers have the same variable names in their code, they won't be considered the same name because the group name will precede the variable name, and each group name is unique. For instance, C++ does not consider the variables:

    group1::apple;
    group100::apple;

    to be the same. The symbol '::' says to go look in that group for the value of the variable.
    Last edited by 7stud; 06-21-2005 at 03:49 PM.

  9. #39
    Registered User
    Join Date
    Jun 2005
    Posts
    15
    Quote Originally Posted by 7stud
    In C++, some variables are put into a group, and the group is given a name. For instance:

    std::cout
    std::cin

    that's what looks different from here and jesse liberty's TYS C++ in 24 hours, he writes it as std::cout instead of cout

    PS great answears, im learning alot

  10. #40
    Registered User
    Join Date
    Jun 2005
    Posts
    15
    Code:
    // custom countdown using while
    #include <iostream.h>
    #include <stdlib.h>
    int main ()
    {
      line6:
      int n;
      char x;
      cout << "Enter the starting number > ";
      cin >> n;
      while (n>0) {
        cout << n << ", ";
        --n;
      }
      cout << "FIRE!";
      cout << "\n" << "Start Again? [Y]es [N]o:";
      cin >> x;
      if (x=='y')
       goto line6;
       else
      system ("PAUSE");
      return 0;
    }
    I took your advise and tried another tutorial, and am working on simpler programs, check it out!

  11. #41
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    >>goto line6;
    OUCH!

    OK, well I assume you're on the while tutorial now. Here's a hint: Replace the goto by putting everything in a big while loop So in other words, you'll have a while loop, with another while loop inside it.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  12. #42
    #include<xErath.h> xErath's Avatar
    Join Date
    Jun 2004
    Posts
    722
    Darth gothpunk... rise...
    Yes master (lord sidious) !!

  13. #43
    Registered User
    Join Date
    Jun 2005
    Posts
    15
    When I was working on the other code and reading the other tutorial, I got some ideas for my first code, I revamped it, it works, but one glich I can't figure out. help any one?
    Code:
    #include <fstream>
    #include <iostream>
    #include <stdio.h>
    #include <time.h>
    #include <stdlib.h>
    
    using namespace std;
    
    int main()
    {
      int a;
      int b;
      b = 100;
      a = sizeof ("example.txt.")*1024;
      char buffer[a];
      char str[b];
      char x;
      ifstream b_file ("example.txt");
      ofstream a_file ("example.txt", ios::app);
    
      while( ! b_file.eof() )
      {
      b_file.getline (buffer, a);
      cout << buffer << "\n";
      }
      here:
      cout << "Like to add anything? [Y]es [N]o" << "\n";
      cin >> x;
      while (x=='y')
      {
      cout << "type now:" << "\n";
      cin >> str;
      cin.getline (  str,  a, ' \n');
      a_file << "\n" << str;
      cout << "\n" << "You added" << "\n" <<str << "\n";
      goto here;
       }
    
    
          system("PAUSE");
          return 0;
    }
    when it gets to "type now:" it skips the first word when it adds it to str, why?

  14. #44
    Registered User MathFan's Avatar
    Join Date
    Apr 2002
    Posts
    190
    Because by doing:
    cin >> str;
    You get only the first characters until you meet a space (or \t or \n etc....) or the end of character space in your string (which is 100). That practically means that you get the first word of the typed-in string.

    But then you overwrite your str variable by getting the rest of the input string, by doing:
    cin.getline ( str, a, ' \n');
    So, the values stored in the string is the whole input string but the first word.

    And, by the way, it should be:

    Code:
     cin.getline (  str,  b, ' \n');
    (remember, your str has only b characters; it is buffer that has a)
    Last edited by MathFan; 06-24-2005 at 02:55 AM.
    The OS requirements were Windows Vista Ultimate or better, so we used Linux.

  15. #45
    Registered User MathFan's Avatar
    Join Date
    Apr 2002
    Posts
    190
    So, what you practically need to do is:

    Code:
    cout << "type now:" << "\n";
    cin.ignore();  //clear the input stream
    cin.getline(str, b, '\n'); //get the line

    goto here;
    Your code shows that you are able to use the while-loop, right? Then you can avoid this. Why not expand your existing loop in a way that it compensates for this goto statement?
    The OS requirements were Windows Vista Ultimate or better, so we used Linux.

Page 3 of 4 FirstFirst 1234 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. noob needs help!!!!:(
    By tykenfitz in forum C Programming
    Replies: 1
    Last Post: 07-10-2005, 08:49 AM
  2. Rtfm
    By XSquared in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 03-13-2003, 04:19 PM
  3. WANTED: Contest Master
    By kermi3 in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-23-2003, 09:15 PM

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