multiset

hi,
I am reading data from a text file into a multiset. After getting all the data into the multiset, I want to compare the value in each element of the container(unsorted) to the previous one.
I tried using an iterator, but unfortunately, the iterator sorts out the values, and the results become meaningless.
how do I run a compare in a multiset of the raw data copied from the text file?
this is the relevant code I have so far:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
std::multiset<int> test;
std::multiset<int>::const_iterator iter;
 std::ifstream p("f.txt");

  if(p.is_open())
    {
       while(p>>x)
      {
	  test.insert(x);
	  std::cout<<"x is: "<<x<<std::endl;
      }
       for(iter=test.begin();iter!=test.end();iter++)
	 std::cout<<"value is "<<*iter<<std::endl; //this shows the data sorted in ascending order
    }
  else std::cout<<"unable to open file! "<<std::endl;


sts::multiset<> is an ordered container. That means it will always appear sorted. If you want an unsorted container then maybe try std::vector<>
Topic archived. No new replies allowed.