User Tools

Site Tools


cpp:stl:container_common_functions

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
cpp:stl:container_common_functions [2021/06/06 20:48] gthanoscpp:stl:container_common_functions [2021/06/08 07:28] – [Β. Ένθεση σε set] gthanos
Line 44: Line 44:
 Σε ένα //associative container// δεν μπορούμε να προσδιορίσουμε τη θέση εισαγωγής του στοιχείου σε αυτόν. Ως εκ τούτου η //insert// δεν λαμβάνει ως πρώτο όρισμα έναν //iterator//. Σε ένα //associative container// δεν μπορούμε να προσδιορίσουμε τη θέση εισαγωγής του στοιχείου σε αυτόν. Ως εκ τούτου η //insert// δεν λαμβάνει ως πρώτο όρισμα έναν //iterator//.
  
-<code cpp string_set_insert.cpp>+<code cpp student_set_insert.cpp>
 #include <iostream>     // std::cout #include <iostream>     // std::cout
 #include <algorithm>    // std::copy #include <algorithm>    // std::copy
-#include <set>       // std::set +#include <set>         // std::set 
-#include <string>+#include "Student.hpp"
  
 int main () { int main () {
-  std::string strings[] = { std::string("gamma"), std::string("beta")std::string("delta") };+  Student students[] = { Student("Peter_Pan", 1234), Student("Tinker_Bell", 1235) };
                                                      
-  std::cerr << "----- Init set -----" << std::endl; +  std::cerr << "----- Init list -----" << std::endl; 
-  std::set<std::stringmyset+  std::set<Studentmylist
-  for(int i=0; i<3; i++)  +  for(int i=0; i<2; i++) { 
-    myset.insert(strings[i]);+    mylist.insert(students[i]);  // copy-constructor, insert first 
 +    mylist.insert(students[i]);    // copy-constructor, insert last 
 +  }
      
-  myset.emplace("alpha");  // argument construct, insert last+  mylist.emplace("Mickey_Mouse", 1237);  // argument construct, insert last
      
   std::cerr << "-------------------------\n";   std::cerr << "-------------------------\n";
-  std::cerr << "myset contains:"; +  std::cerr << "mylist contains:"; 
-  for (std::set<std::string>::iterator it = myset.begin(); it!=myset.end(); it++)+  for (std::set<Student>::iterator it = mylist.begin(); it!=mylist.end(); ++it)
     std::cerr << ' ' << *it;     std::cerr << ' ' << *it;
   std::cerr << std::endl;   std::cerr << std::endl;
cpp/stl/container_common_functions.txt · Last modified: 2023/05/30 19:18 by gthanos