little code probelm

hey everyone, i believe i'm having a brain fart because i cant see whats wrong with this part of my code it compiles fine but it doesn't output the string when it should. its checking to see if there are duplicates of an found email. thanks for the help =).

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
bool emailAlreadyExists = false;

//stating point of the check
  for (int i = 0; i < nEmails; i++) 
   {
	string temp1=email[i];
//change to lower
     class toLower {public: char operator()(char c) const {return tolower(c);}};
	transform(temp1.begin(), temp1.end(), temp1.begin(), toLower());
//check against others in the array
	for (int j=i+1;j<=nEmails;j++)
	{
//create temp2 code
	  string temp2=email[j];
//change to lower
          transform(temp2.begin(), temp2.end(), temp2.begin(), toLower());
//if it is equal change to true
       if (temp1 == temp2) emailAlreadyExists = true;
	  {
		  break;
	  }//if
        }//for 


// if non-duplicate,print to screen
if (!emailAlreadyExists) 
  {
   cout<<email[i]<<";"<<endl;
  }//if
}//while 
Last edited on
Hi,
C++ does not support local functor classes for template algorithms. For instance, see the article:
http://www.informit.com/articles/article.aspx?p=345948&seqNum=3

If you declare the functor in the header, your code works.

mm
This code has no any sense

string temp1=email[i];
//change to lower
class toLower {public: char operator()(char c) const {return tolower(c);}};
transform(temp1.begin(), temp1.end(), temp1.begin(), toLower());


You define a string and assign it only one character email[i]. Then you use standard algorithm std::transfrom. Why do you can not simply to write

string temp1 = std::tolower( email[i] );
Topic archived. No new replies allowed.