Jump to content

rufidmonki

Member
  • Posts

    38
  • Joined

  • Last visited

Reputation Activity

  1. Like
    rufidmonki got a reaction from adelhied in More advanced HTML & CSS   
    I recommend you to actually start CREATING something.
     
    Try to make a website using what you've learned.
    Maybe you could try to add some JavaScript while you're at it?
     
    You should also start looking at PHP. Right now. (That is, if you're serious about web development)
    Search for some YouTube tutorials to get started.
  2. Like
    rufidmonki got a reaction from alpenwasser in C-style strings vs library strings   
    With C-style strings, you need to reallocate when changing the string. There's a more direct handling of the string. An std::string has operators for all of this already. You could make your own string class however. "rexlee_string" or something. However, that would require a lot of work from your side in optimising it. It also sounds like you're new to C++/programming, so that would be highly unrecommendable.

    Here's an example:
    char* mycstring = "My C-string";char* yourcstring = "Your C-string";std::cout << mycstring + yourcstring; Now, that creates a problem because mycstring and yourcstring are POINTERS. And also, it's an array, and the c-string is the pointer to the first index.
    If you allocated more memory for your c-string and don't delete it before it goes out of scope, you've got yourself a memory leak.
    It's much easier with std::string, as you can use the operators as with a number. (well, not - * and / etc) and it deals with all the dynamic stuff itself.

    There comes a point where you need to use char arrays though. A buffer for instance. Maybe for networking or filereading/writing.
    (Though, there's a C++ alternative for this too, called std::stringstream, you should look it up - it's very useful sometimes)

    As for your second question, it depends.
    If you want an array that only needs, let's say 10 elements, then you should go for a static array. "int myarray [10];"
    However, if you're not sure how many elements you need, you should go for an std::vector.
    When you're using polymorphism or have another need for pointers in the vector, use the new operator and pointers as the vector type. If you don't need a pointer, just make it an std::vector<int>, for example.

    I am not a fan of iterators however. I have never ever used them to be honest. They do have a use, but it's really rare and you usually don't have to use them.
    A typical loop to iterate over all elements in a vector should look like this:
    unsigned int vectorsize = myvector.size();for (unsigned int i = 0; i < vectorsize; i++) { std::cout << myvector[i];} Well, honestly I never assign the size to a variable, but it's faster in some cases.

    So yeah. static arrays should be normal arrays, but vectors are very good for dynamic arrays. Just the same way C++ strings are good for dynamic strings. :)

    It makes everything less tedious.

    Hope I was at help.

    ~dib
  3. Like
    rufidmonki got a reaction from Darkfeign in C-style strings vs library strings   
    With C-style strings, you need to reallocate when changing the string. There's a more direct handling of the string. An std::string has operators for all of this already. You could make your own string class however. "rexlee_string" or something. However, that would require a lot of work from your side in optimising it. It also sounds like you're new to C++/programming, so that would be highly unrecommendable.

    Here's an example:
    char* mycstring = "My C-string";char* yourcstring = "Your C-string";std::cout << mycstring + yourcstring; Now, that creates a problem because mycstring and yourcstring are POINTERS. And also, it's an array, and the c-string is the pointer to the first index.
    If you allocated more memory for your c-string and don't delete it before it goes out of scope, you've got yourself a memory leak.
    It's much easier with std::string, as you can use the operators as with a number. (well, not - * and / etc) and it deals with all the dynamic stuff itself.

    There comes a point where you need to use char arrays though. A buffer for instance. Maybe for networking or filereading/writing.
    (Though, there's a C++ alternative for this too, called std::stringstream, you should look it up - it's very useful sometimes)

    As for your second question, it depends.
    If you want an array that only needs, let's say 10 elements, then you should go for a static array. "int myarray [10];"
    However, if you're not sure how many elements you need, you should go for an std::vector.
    When you're using polymorphism or have another need for pointers in the vector, use the new operator and pointers as the vector type. If you don't need a pointer, just make it an std::vector<int>, for example.

    I am not a fan of iterators however. I have never ever used them to be honest. They do have a use, but it's really rare and you usually don't have to use them.
    A typical loop to iterate over all elements in a vector should look like this:
    unsigned int vectorsize = myvector.size();for (unsigned int i = 0; i < vectorsize; i++) { std::cout << myvector[i];} Well, honestly I never assign the size to a variable, but it's faster in some cases.

    So yeah. static arrays should be normal arrays, but vectors are very good for dynamic arrays. Just the same way C++ strings are good for dynamic strings. :)

    It makes everything less tedious.

    Hope I was at help.

    ~dib
  4. Like
    rufidmonki got a reaction from Prettyfinej in New To Programming. Where the heck do I begin?   
    I recommend starting with basic C++ in Visual Studio 2012 Express (free): http://go.microsoft.com/?linkid=9816758
    Here is a link with some tutorials: http://www.cplusplus.com/doc/tutorial/
    When you are on a tutorial, do NOT go to the next one until you completely understand the one you're working on.
    For example; on the first tutorial - "structure of a program".
    You might know what "cout" does, it prints text to the console, right? But do you know what happens if you remove "using namespace std;" ?
    The program won't compile, right? Well, if you add "std::" in front of "cout", it suddenly will again, because "cout" is a member of the "std" namespace. The "using namespace std;", easily put, removes the need to write std:: manually, but this isn't a good practice as you could encounter libraries or your own code having the same names for stuff and will mix with std. So it's always good to use a namespace or/and a prefix for functions and classes. Class functions are okay as they basically use the class as a namespace.
    So it's stuff like this that I mean you should understand.
    When you are ready to get into graphics, you usually just get into it. If you start searching randomly - you won't get anywhere. Trust me. ;( xD (unless it's easier to find now)
    Hope this helps, and good luck! :)
    (if you need help with something, you can always add me on Skype - gammaray24)
×