I haven't had time to post questions for a while so i have accumulated many questions.
1)What is the advantage of auto? it either takes (I know its slight but still)more time to write it or the time (1 second) is lost during compile time
2)same with strcopy(). why not just initialize it to that
3)besides changing arguements passed to functions and changing object members instead of the whole object, what advantage do pointers and references give?
4)what is a more, shall i say better, form of system("CLEAR")?
5)Can someone explain hexadecimal, octal, and binary numbering systems?
1) auto can be useful when dealing with templates and there is no way to know what the result of something is. T1 a; T2 b; what is the type of a + b? You don't know but you can still get the correct type with auto: auto c = a + b;.
It can also be used to avoid having to type very long and complicated types such as iterators. Don't use auto all over the place just because you can. It's nice to be able to look at the code and see the type of something.
2) You mean strcpy, right? If you want to copy a c string you don't have much other ways of copying a string.
3) A linked list is a good example where you need pointers. Try write one without and you will fail. I'm serious, do it!
4) There is no way in standard C++ to do that. You might want to use a library such as ncurses to do it.
3 - If you have huge objects you're passing around all over the place then using a reference rather than a copy of that object will optimize your code. There are a billion reasons why pointers and references are essential to c++... I don't even know what to say.
4 - Maybe ShellExecute if you're coding on windows?
5 - hex, octal and binary are just like the base-10 decimal number system you're used to. Each is composed of places. In decimal, each place can contain the numbers 0-9 (10 numbers (0 might not be a number though... but come on...)). In hex each place can contain the numbers 0-9 and then A - F which is a total of 16 numbers per place. In octal the places can have numbers 0-7, 8 numbers per place. Binary gets 0-1 per place. If you had 16 fingers, counting in hex would be super easy lol.
1) It takes me more than one second to declare an iterator to a vector.
1) You can also use auto for anonymous types (like lambda functions).
auto func = [](){ return; };
1) auto allows you to refer to as yet unknown types in templates.
2) strcpy()? Why not just use std::string?
3) Passing by pointer or reference does not copy the whole object.
3) Pointers allow you to dynamically create objects.
3) Pointers don't have to point to anything.
3) References facilitate overloading of certain operators.
3) References must be bound to an object at creation.
4) Get used to starting with your terminal's previous output.
6) These are just ways to get input from a file or output to a file.
1 2 3 4 5 6 7 8 9 10
std::ifstream ifs("input.txt"); // open file for input
std::ofstream ofs("output.txt"); // open file for output
std::string line; // string to hold each line from the file
while(std::getline(ifs, line)) // read each line from the input file
{
ofs << line << '\n'; << write the line to the output file
}