std::sort in vector returns 0 instead of the values [duplicate] Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experience Should we burninate the [wrap] tag?Setting vector elements in range-based for loopWhy use static_cast<int>(x) instead of (int)x?Initializing a static std::map<int, int> in C++How to concatenate a std::string and an int?Concatenating two std::vectorsHow to find out if an item is present in a std::vector?What is the easiest way to initialize a std::vector with hardcoded elements?C++ : push_back a map<string, int> into a vector<map<string, int> > via an iterator?How can I get sizeof a vector::value_type?Operator “<<” overloading return typeHow to find the minimum element in vector of pairs in c++?

What is the musical term for a note that continously plays through a melody?

Examples of mediopassive verb constructions

How to assign captions for two tables in LaTeX?

Should I use Javascript Classes or Apex Classes in Lightning Web Components?

Do I really need recursive chmod to restrict access to a folder?

What would be the ideal power source for a cybernetic eye?

Disable hyphenation for an entire paragraph

What is the longest distance a 13th-level monk can jump while attacking on the same turn?

What are 'alternative tunings' of a guitar and why would you use them? Doesn't it make it more difficult to play?

Is there a service that would inform me whenever a new direct route is scheduled from a given airport?

Is there a Spanish version of "dot your i's and cross your t's" that includes the letter 'ñ'?

Is the address of a local variable a constexpr?

Should I discuss the type of campaign with my players?

Sorting numerically

Does accepting a pardon have any bearing on trying that person for the same crime in a sovereign jurisdiction?

Why is black pepper both grey and black?

When -s is used with third person singular. What's its use in this context?

Why was the term "discrete" used in discrete logarithm?

Is a manifold-with-boundary with given interior and non-empty boundary essentially unique?

What is the correct way to use the pinch test for dehydration?

Storing hydrofluoric acid before the invention of plastics

How to deal with a team lead who never gives me credit?

What's the purpose of writing one's academic bio in 3rd person?

Output the ŋarâþ crîþ alphabet song without using (m)any letters



std::sort in vector returns 0 instead of the values [duplicate]



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
The Ask Question Wizard is Live!
Data science time! April 2019 and salary with experience
Should we burninate the [wrap] tag?Setting vector elements in range-based for loopWhy use static_cast<int>(x) instead of (int)x?Initializing a static std::map<int, int> in C++How to concatenate a std::string and an int?Concatenating two std::vectorsHow to find out if an item is present in a std::vector?What is the easiest way to initialize a std::vector with hardcoded elements?C++ : push_back a map<string, int> into a vector<map<string, int> > via an iterator?How can I get sizeof a vector::value_type?Operator “<<” overloading return typeHow to find the minimum element in vector of pairs in c++?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1
















This question already has an answer here:



  • Setting vector elements in range-based for loop

    4 answers



Im doing a simple exercise in HackerRank, get some ints in a vector and print them sorted in the screen.



int main() 
int sz;
std::cin >> sz; // 5 in this case

std::vector<int> v(sz);
for(auto elem : v)
std::cin >> elem;
std::cout << elem << ' '; //1 6 10 8 4

std::cout << std::endl;

std::sort(v.begin(), v.end());

for (auto elem : v)
std::cout << elem << ' '; //0 0 0 0 0

return 0;



The output is:



1 6 10 8 4 
0 0 0 0 0


Is there something else to take in account with the std::sort? Is it a problem with HackerRank's compiler?










share|improve this question















marked as duplicate by Slava c++
Users with the  c++ badge can single-handedly close c++ questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 8 at 16:30


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
























    1
















    This question already has an answer here:



    • Setting vector elements in range-based for loop

      4 answers



    Im doing a simple exercise in HackerRank, get some ints in a vector and print them sorted in the screen.



    int main() 
    int sz;
    std::cin >> sz; // 5 in this case

    std::vector<int> v(sz);
    for(auto elem : v)
    std::cin >> elem;
    std::cout << elem << ' '; //1 6 10 8 4

    std::cout << std::endl;

    std::sort(v.begin(), v.end());

    for (auto elem : v)
    std::cout << elem << ' '; //0 0 0 0 0

    return 0;



    The output is:



    1 6 10 8 4 
    0 0 0 0 0


    Is there something else to take in account with the std::sort? Is it a problem with HackerRank's compiler?










    share|improve this question















    marked as duplicate by Slava c++
    Users with the  c++ badge can single-handedly close c++ questions as duplicates and reopen them as needed.

    StackExchange.ready(function()
    if (StackExchange.options.isMobile) return;

    $('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
    var $hover = $(this).addClass('hover-bound'),
    $msg = $hover.siblings('.dupe-hammer-message');

    $hover.hover(
    function()
    $hover.showInfoMessage('',
    messageElement: $msg.clone().show(),
    transient: false,
    position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
    dismissable: false,
    relativeToBody: true
    );
    ,
    function()
    StackExchange.helpers.removeMessages();

    );
    );
    );
    Mar 8 at 16:30


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.




















      1












      1








      1









      This question already has an answer here:



      • Setting vector elements in range-based for loop

        4 answers



      Im doing a simple exercise in HackerRank, get some ints in a vector and print them sorted in the screen.



      int main() 
      int sz;
      std::cin >> sz; // 5 in this case

      std::vector<int> v(sz);
      for(auto elem : v)
      std::cin >> elem;
      std::cout << elem << ' '; //1 6 10 8 4

      std::cout << std::endl;

      std::sort(v.begin(), v.end());

      for (auto elem : v)
      std::cout << elem << ' '; //0 0 0 0 0

      return 0;



      The output is:



      1 6 10 8 4 
      0 0 0 0 0


      Is there something else to take in account with the std::sort? Is it a problem with HackerRank's compiler?










      share|improve this question

















      This question already has an answer here:



      • Setting vector elements in range-based for loop

        4 answers



      Im doing a simple exercise in HackerRank, get some ints in a vector and print them sorted in the screen.



      int main() 
      int sz;
      std::cin >> sz; // 5 in this case

      std::vector<int> v(sz);
      for(auto elem : v)
      std::cin >> elem;
      std::cout << elem << ' '; //1 6 10 8 4

      std::cout << std::endl;

      std::sort(v.begin(), v.end());

      for (auto elem : v)
      std::cout << elem << ' '; //0 0 0 0 0

      return 0;



      The output is:



      1 6 10 8 4 
      0 0 0 0 0


      Is there something else to take in account with the std::sort? Is it a problem with HackerRank's compiler?





      This question already has an answer here:



      • Setting vector elements in range-based for loop

        4 answers







      c++






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 8 at 16:25







      Pepe Moreno

















      asked Mar 8 at 16:19









      Pepe MorenoPepe Moreno

      614




      614




      marked as duplicate by Slava c++
      Users with the  c++ badge can single-handedly close c++ questions as duplicates and reopen them as needed.

      StackExchange.ready(function()
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function()
      $hover.showInfoMessage('',
      messageElement: $msg.clone().show(),
      transient: false,
      position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
      dismissable: false,
      relativeToBody: true
      );
      ,
      function()
      StackExchange.helpers.removeMessages();

      );
      );
      );
      Mar 8 at 16:30


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









      marked as duplicate by Slava c++
      Users with the  c++ badge can single-handedly close c++ questions as duplicates and reopen them as needed.

      StackExchange.ready(function()
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function()
      $hover.showInfoMessage('',
      messageElement: $msg.clone().show(),
      transient: false,
      position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
      dismissable: false,
      relativeToBody: true
      );
      ,
      function()
      StackExchange.helpers.removeMessages();

      );
      );
      );
      Mar 8 at 16:30


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
























          1 Answer
          1






          active

          oldest

          votes


















          6














          elem is a copy of the items in your vector! Change it to be a reference so you'll actually be modifying the vector when reading in values:



          for(auto &elem : v)
          // ^^^
          std::cin >> elem;
          std::cout << elem << ' '; //1 6 10 8 4



          See it work here: ideone






          share|improve this answer























          • Yes it was that, thanks!

            – Pepe Moreno
            Mar 8 at 16:25

















          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          6














          elem is a copy of the items in your vector! Change it to be a reference so you'll actually be modifying the vector when reading in values:



          for(auto &elem : v)
          // ^^^
          std::cin >> elem;
          std::cout << elem << ' '; //1 6 10 8 4



          See it work here: ideone






          share|improve this answer























          • Yes it was that, thanks!

            – Pepe Moreno
            Mar 8 at 16:25















          6














          elem is a copy of the items in your vector! Change it to be a reference so you'll actually be modifying the vector when reading in values:



          for(auto &elem : v)
          // ^^^
          std::cin >> elem;
          std::cout << elem << ' '; //1 6 10 8 4



          See it work here: ideone






          share|improve this answer























          • Yes it was that, thanks!

            – Pepe Moreno
            Mar 8 at 16:25













          6












          6








          6







          elem is a copy of the items in your vector! Change it to be a reference so you'll actually be modifying the vector when reading in values:



          for(auto &elem : v)
          // ^^^
          std::cin >> elem;
          std::cout << elem << ' '; //1 6 10 8 4



          See it work here: ideone






          share|improve this answer













          elem is a copy of the items in your vector! Change it to be a reference so you'll actually be modifying the vector when reading in values:



          for(auto &elem : v)
          // ^^^
          std::cin >> elem;
          std::cout << elem << ' '; //1 6 10 8 4



          See it work here: ideone







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 8 at 16:22









          scohe001scohe001

          8,32212442




          8,32212442












          • Yes it was that, thanks!

            – Pepe Moreno
            Mar 8 at 16:25

















          • Yes it was that, thanks!

            – Pepe Moreno
            Mar 8 at 16:25
















          Yes it was that, thanks!

          – Pepe Moreno
          Mar 8 at 16:25





          Yes it was that, thanks!

          – Pepe Moreno
          Mar 8 at 16:25





          Popular posts from this blog

          Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

          Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

          Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved