0

Vector, sort() error!!

Initially a vector named number is empty. This program is supposed to take input(numbers of type double) from the user to store in the vector (named numbers). The problem here is the statement sort(numbers)[line no.60 in my code]. As there are no values initially in the vector, the statement sort(numbers) create a build error! Please help me get out of this situation. https://code.sololearn.com/cR5U4LawMhSe/?ref=app //It might be problematic to run this code on mobile

9th Jul 2019, 6:21 PM
Chetan Satpute
Chetan Satpute - avatar
4 Antworten
0
Chetan Satpute sorry, my mistake. Just add sort(number.begin(), number.end()); https://code.sololearn.com/cz3SPqqIGq1n/?ref=app I did one example of vector sorting
10th Jul 2019, 2:47 PM
Dejan Francuz🥇
Dejan Francuz🥇 - avatar
+ 1
Unfortunately, here, you can't do the thing you wanted, but you can sort the vector like this for(auto x:number){ cout<<x<<endl; }
9th Jul 2019, 10:28 PM
Dejan Francuz🥇
Dejan Francuz🥇 - avatar
+ 1
Dejan Francuz thank you, it worked.
10th Jul 2019, 3:09 PM
Chetan Satpute
Chetan Satpute - avatar
0
#Dejan Francuz for (auto x : number ) { cout <<x<<endl; } Just prints the value in vector it does not sort them Please help
10th Jul 2019, 1:43 PM
Chetan Satpute
Chetan Satpute - avatar