File is successfully opened
3 13 34 54 71 81 97 105 116 135 138
I have this data, and I want to call (3,1) then (3,13), then (3,34)..........

How to declare 3 is the first than 13 is second?

{	ifstream stream1 ("STA83STU.txt");
		if ( !stream1 )
		
		{
    	stream1.close (); 
		}
		const int student_size = 12;
		pair<int,int>* array[student_size];
		for (int k = 0; k< student_size; k++)   	
		 
		{
		array[k] = new pair<int,int>(1,k); // Construct each new pair and give its address to an index in the pointer arrayconst int student_size = 12;
		cout <<"("<<"  , k" << ")";
		cout <<"\n"<<endl;
		}

	}

Recommended Answers

All 2 Replies

something like this...

#include <string.h>
#include <iostream>
#include <map>
#include <utility>
using namespace std;
int main()
{  
// Compare (<) function not required since it is built into string class.
  // else declaration would comparison function in multimap definition.  
  // i.e. multimap<string, int, compare> m; 
   multimap<string, int> m; 
    m.insert(pair<string, int>("a", 1)); 
	 m.insert(pair<string, int>("c", 2)); 
	  m.insert(pair<string, int>("b", 3)); 
	   m.insert(pair<string, int>("b", 4)); 
	    m.insert(pair<string, int>("a", 5)); 
		 m.insert(pair<string, int>("b", 6)); 
		  cout << "Number of elements with key a: " << m.count("a") << endl; 
		   cout << "Number of elements with key b: " << m.count("b") << endl; 
		    cout << "Number of elements with key c: " << m.count("c") << endl; 
			 cout << "Elements in m: " << endl;
			   for (multimap<string, int>::iterator it = m.begin(); it != m.end();  ++it)  
			    {      
				 cout <<"["<<(*it).first<<","<<(*it).second<<"]"<<endl;  
				  }  
				   pair<multimap<string, int>::iterator, multimap<string, int>::iterator> ppp;   
				   // equal_range(b) returns pair<iterator,iterator> representing the range  
				    // of element with key b   ppp = m.equal_range("b");   
					// Loop through range of maps of key "b"  
				   cout << endl << "Range of \"b\" elements:" << endl; 
					  for (multimap<string, int>::iterator it2 = ppp.first;  it2 != ppp.second;  ++it2)  
					   {       
					   cout << "  [" << (*it2).first << ", " << (*it2).second << "]" << endl; 
					    }
						// Can't do this (??)
					  //  	 cout << ppp.first << endl;
						 //  cout << ppp.second << endl; 
						   m.clear();
					  }

When are you going to learn to explain what you want in understandable terms? "I want to call (3,1) then (3,13), then (3,34).........." means what? What does "call" mean?

"How to declare 3 is the first than 13 is second?" is also meaningless. The first what? The second what?

Give us a full explanation of what you are trying to accomplish.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.