i am using #include <algorithm> to call upon to sort()
i keep geting a runtime error when i try sorting my vector.
does anybody know on how i can fix this or have a good function for sorting a vector ?
if anybody needs the full source i can give it , i just didnt want to post it due to so many lines of code
let me rephrase my question then
i tried to aproach this program using arrays instead vector
the problem is when i call the array i get this in my debuger
that error C2057: expected constant expression
#include <iostream>
using namespace std;
int main()
{
int numele=2;
cin >> numele;
int elenum = numele;
float molarnum[elenum];
}
i tried using vectors to state this array is there a way i can fix this
sorry that i was not clear
That is because arrays in C++ have a fixed size. You are trying to use variable length arrays, which do not exist in standard C++. Since you already tried with vectors, why not use them?
C + C++ Compiler: MinGW port of GCC
Build + Version Control System: SCons + Bazaar
There's a new STL container called array coming up in the new C++ standard.
I was aware of that, but the point of the example was to use the vector, not the array, so my note is concerning the fact that the array is purely to make initialisation of the vector easier in the absence of the initialisation syntax to be introduced by C++0x, despite the fact that the array alone would otherwise suffice for an example.
C + C++ Compiler: MinGW port of GCC
Build + Version Control System: SCons + Bazaar
I was aware of that, but the point of the example was to use the vector, not the array, so my note is concerning the fact that the array is purely to make initialisation of the vector easier in the absence of the initialisation syntax to be introduced by C++0x, despite the fact that the array alone would otherwise suffice for an example.
I just wanted to add some information.
This new STL container called "array" will retire STL vector as the preferred replacement for C style arrays.
Last edited by _uj; January 20th, 2009 at 12:11 PM.
This new STL container called "array" will retire STL vector as the preferred replacement for C style arrays.
Generally, yes. However, in view that michael1991j attempted to use variable length arrays in C++, I daresay that std::vector is more appropriate here.
Originally Posted by kempofighter
That's fabulous. No offense, but how does that help us at the present time using compilers that do not implement the new standard?
The array container is available in TR1, of which there are existing implementations. That said, we are detracting from the topic of this thread.
C + C++ Compiler: MinGW port of GCC
Build + Version Control System: SCons + Bazaar
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.