Today, I was learning about Memory Allocation, using new and delete.
However,when I made a test program, the value wasn't what I wanted it to be.
c++:
#include <iostream> usingnamespace std;
int main() { int number;
cin >> number;
int *ptr_number = newint[number];//I tried to assign *ptr_numbers the value of number cout << *ptr_number;//The output wasn't what I entered though }
The STL (Standard Template Library) is not for the faint of heart. It makes deep use of templates, which are tricky, and do not result in pleasant error messages.
Teachers avoid it because C++ is complicated enough to teach as it is, but also because many employers who hire programmers to work in C++ also avoid it. To some extent that situation is a chicken and egg problem.
for (int i = 0; i < 10; i++)
{
std::cout << foo[i] << std::endl;
}
return 0;
}
I saw that in my ebook already, thanks anyways
The example I saw didn't say it was for arrays, so I was kind of confused.
Btw, is there a way to delete a non-integer pointer? Since I can't do something like this:
c++:
POINT *cursorpos = new POINT[amount];
since it's not an enum or integer... is it even possible to get memory from the free store for the structure POINT?
Edit: Nevermind, reread it.. what does this do?
code:
std::fill(foo, foo + 10, 0);
and what does the algorithm header file allow me to do?
Including <algorithm> lets you use a bunch of useful, generalized functions, like swapping, sorting, searching, etc. You can find a description of all these algorithms (including fill) at http://www.cplusplus.com/reference/algorithm/
The STL (Standard Template Library) is not for the faint of heart. It makes deep use of templates, which are tricky, and do not result in pleasant error messages.
Teachers avoid it because C++ is complicated enough to teach as it is, but also because many employers who hire programmers to work in C++ also avoid it. To some extent that situation is a chicken and egg problem.
What do you mean by The STL is not for the faint of heart? like it's just really hard?
Should I even bother with it then?
The STL requires a reasonably deep knowledge of C++. Of course, trying to figure it out can be a good incentive to investigate the more interesting concepts in C++.