need std::map for this question


First Of all I would like to thank Michael Thomas Greer (Duoas ) for his endless help in the forum and to me specially .

I have like this in a file1.txt

OK Green > start 1                
OK Green > start 2                
No Green > start 3               

OK orange > start 1               
No orange > start 2               
No orange > start 3             

OK red > start 1                  
OK red > start 2                  
OK red > start 3  




File2.txt has this

OK Green > start 1 
No Green > start 2
Ok Green > start 3
No orange > start 1
Ok orange > start 2
No orange > start 3
OK red > start 1
OK red > start 2
No red > start 3
OK Green > start 1// note: the content of file1 again start from here
Ok Green > start 2
No Green > start 3
OK orange > start 1
No orange > start 2
No orange > start 3
OK red > start 1
OK red > start 2
OK red > start 3



how to make a function check() using std:map to do this :

for ex-

if (2 statements in file2.txt[18 commands] (Green Green) and (OK OK) return true

if both(Green Green)in file2.txt and (OK NO) return True

if both(Green Green) in file2.txt and (No Ok) return False

if both(Green Green) in file2.txt and (No No) return False

How can we do a compatible check for file1 as well as long it works properly with file2 ?? can be ;)


I think the associative map should have the (color + start_id) as the key, and the number of "OK" instances as the value.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
void readfile(int id)
{
const unsigned int FIELDS = 5;
const unsigned int RECORDS = 18;//change here
std::string P2[RECORDS][FIELDS];
	
	char filename[ 1024 ];
	sprintf( filename, "file%d.txt", id );	//1
	ifstream myfile (filename);
	
  	if (myfile.is_open())
  	{
		std::cout << "Opened " << filename << " for reading." << std::endl;
		int i = 0;
		while (!myfile.eof()) // 
    		{
    			myfile >> P2[i][0] >>
    				  P2[i][1] >>
    				  P2[i][2] >>
    				  P2[i][3] >>
    				  P2[i][4];
    			++i;
    		}
	}
	else
	{
     		std::cout << "There was a problem opening the file " << filename << " for reading." << std::endl;

  	}
	
}
Last edited on
Topic archived. No new replies allowed.