What does this error mean?

P

Protoman

I'm getting an error:

10 C:\Dev-Cpp\Enigma.cpp no match for 'operator<' in 'i <
(+cleartext)->std::basic_string<_CharT, _Traits, _Alloc>::end [with
_CharT = char, _Traits = std::char_traits<char>, _Alloc =
std::allocator<char>]()'

Code:

Enigma.hpp
--------------------------
#pragma once
#include <string>
using namespace std;
class Rotor
{
public:
Rotor(char pos=0):CurPos(0),steps(0)
{
memcpy(Alphabet,"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",36);
SetRotorPosition(CharacterMap(pos));
}
int GetSteps(){return steps;}
int CharacterMap(char Char)
{
if(Char=='A')
return 0;
else if(Char=='B')
return 1;
else if(Char=='C')
return 2;
else if(Char=='D')
return 3;
else if(Char=='E')
return 5;
else if(Char=='F')
return 6;
else if(Char=='G')
return 7;
else if(Char=='H')
return 8;
else if(Char=='I')
return 9;
else if(Char=='J')
return 10;
else if(Char=='K')
return 11;
else if(Char=='L')
return 12;
else if(Char=='M')
return 13;
else if(Char=='N')
return 14;
else if(Char=='O')
return 15;
else if(Char=='P')
return 16;
else if(Char=='Q')
return 17;
else if(Char=='R')
return 18;
else if(Char=='S')
return 19;
else if(Char=='T')
return 20;
else if(Char=='U')
return 21;
else if(Char=='V')
return 22;
else if(Char=='W')
return 23;
else if(Char=='X')
return 24;
else if(Char=='Y')
return 25;
else if(Char=='Z')
return 26;
else if(Char=='0')
return 27;
else if(Char=='1')
return 28;
else if(Char=='2')
return 29;
else if(Char=='3')
return 30;
else if(Char=='4')
return 31;
else if(Char=='5')
return 32;
else if(Char=='6')
return 33;
else if(Char=='7')
return 34;
else if(Char=='8')
return 35;
else if(Char=='9')
return 36;
}
void SetRotorPosition(int NewPos)
{
while(NewPos < 0)
{
NewPos +=36;
}
CurPos = NewPos%36;
}
void AdvanceRotor(int Steps)
{
CurPos += Steps;
while(CurPos < 0)
{
CurPos +=36;
}
CurPos %=36;
steps++;
}
void ReverseRotor(int Steps)
{
AdvanceRotor(-Steps);
steps--;
}
char GetCurrentCharacter()
{
return Alphabet[CurPos];
}
char GetCharacterIndex(int Index)
{
return Alphabet[(CurPos+Index)%36];
}
private:
char Alphabet[36];
int CurPos;
int steps;
};
class Enigma
{
public:
Enigma(char r1,char r2,char r3,char r4,char r5,char ref):
R1(r1),R2(r2),R3(r3),R4(r4),R5(r5),Ref(ref){}
~Enigma(){}
string Encrypt(const string& cleartext);
private:
Rotor R1;
Rotor R2;
Rotor R3;
Rotor R4;
Rotor R5;
Rotor Ref;
};

Enigma.cpp
-------------------------------
#include "Enigma.hpp"
#include <string>
using namespace std;

string Enigma::Encrypt(const string& cleartext)
{
string ciphertext;
ciphertext.resize(cleartext.size());
int i=0;
for(;i<cleartext.end();i++)
{
int val=Rotor().CharacterMap(cleartext);
char val1=R1.GetCharacterIndex(val);
R1.AdvanceRotor(1);
int val2=Rotor().CharacterMap(val1);
char val3=R2.GetCharacterIndex(val2);
if(R1.GetSteps()==36)
R2.ReverseRotor(1);
int val4=Rotor().CharacterMap(val3);
char val5=R3.GetCharacterIndex(val4);
if(R2.GetSteps()==-36)
R3.AdvanceRotor(1);
int val6=Rotor().CharacterMap(val5);
char val7=R4.GetCharacterIndex(val6);
if(R3.GetSteps()==36)
R4.ReverseRotor(1);
int val8=Rotor().CharacterMap(val7);
char val9=R5.GetCharacterIndex(val8);
if(R4.GetSteps()==-36)
R5.AdvanceRotor(1);
int val10=Rotor().CharacterMap(val9);
char val11=Ref.GetCharacterIndex(val10);
if(R5.GetSteps()==36)
Ref.ReverseRotor(1);
int val12=Rotor().CharacterMap(val11);
char val13=R5.GetCharacterIndex(val12);
int val14=Rotor().CharacterMap(val13);
char val15=R4.GetCharacterIndex(val14);
int val16=Rotor().CharacterMap(val15);
char val17=R3.GetCharacterIndex(val16);
int val18=Rotor().CharacterMap(val17);
char val19=R2.GetCharacterIndex(val18);
int val20=Rotor().CharacterMap(val19);
char val21=R1.GetCharacterIndex(val20);
ciphertext=val21;
}
return ciphertext;
}

What does it mean and how should I fix it? Thanks!!!!
 
G

Gianni Mariani

Protoman said:
I'm getting an error:

10 C:\Dev-Cpp\Enigma.cpp no match for 'operator<' in 'i <
(+cleartext)->std::basic_string<_CharT, _Traits, _Alloc>::end [with
_CharT = char, _Traits = std::char_traits<char>, _Alloc =
std::allocator<char>]()'

Code: ....snipped...
What does it mean and how should I fix it? Thanks!!!!

I think the line of code is this:
for(;i<cleartext.end();i++)

What does

operator<( int, std::stding::iterator )

mean ?

Perhaps you mean
for(;i<cleartext.length();i++)
 
J

Jim Langston

Gianni Mariani said:
Protoman said:
I'm getting an error:

10 C:\Dev-Cpp\Enigma.cpp no match for 'operator<' in 'i <
(+cleartext)->std::basic_string<_CharT, _Traits, _Alloc>::end [with
_CharT = char, _Traits = std::char_traits<char>, _Alloc =
std::allocator<char>]()'

Code: ...snipped...
What does it mean and how should I fix it? Thanks!!!!

I think the line of code is this:
for(;i<cleartext.end();i++)

What does

operator<( int, std::stding::iterator )

mean ?

Perhaps you mean
for(;i<cleartext.length();i++)

I didn't go thorugh all that code, but from the error snippet it appears
you're trying to compare an integer with an iterator. Can't do that. i
would need to be an iterator itself.
 
P

Protoman

Jim said:
Gianni Mariani said:
Protoman said:
I'm getting an error:

10 C:\Dev-Cpp\Enigma.cpp no match for 'operator<' in 'i <
(+cleartext)->std::basic_string<_CharT, _Traits, _Alloc>::end [with
_CharT = char, _Traits = std::char_traits<char>, _Alloc =
std::allocator<char>]()'

Code: ...snipped...
What does it mean and how should I fix it? Thanks!!!!

I think the line of code is this:
for(;i<cleartext.end();i++)

What does

operator<( int, std::stding::iterator )

mean ?

Perhaps you mean
for(;i<cleartext.length();i++)

I didn't go thorugh all that code, but from the error snippet it appears
you're trying to compare an integer with an iterator. Can't do that. i
would need to be an iterator itself.

OK, fixed that, here's the main program:

EnigmaMain.cpp
----------------------------------
#include "Enigma.hpp"
#include <iostream>
#include <cstdlib>
using namespace std;

int main()
{
start:
string cleartext;
char R1,R2,R3,R4,R5,Ref;
cout << "Enter the rotor and reflector settings: ";
cin >> R1 >> R2 >> R3 >> R4 >> R5 >> Ref;
Enigma encrypter(R1,R2,R3,R4,R5,Ref);
cin.ignore(1);
cout << "Enter cleartext: " << endl;
getline(cin,cleartext);
string ciphertext(encrypter.Encrypt(cleartext));
cout << "Ciphertext: " << ciphertext << endl;
goto start;
system("PAUSE");
return EXIT_SUCCESS;
}

It compiles and links just fine, but why won't the ciphertext appear?
 
P

Protoman

Protoman said:
Jim said:
Gianni Mariani said:
Protoman wrote:
I'm getting an error:

10 C:\Dev-Cpp\Enigma.cpp no match for 'operator<' in 'i <
(+cleartext)->std::basic_string<_CharT, _Traits, _Alloc>::end [with
_CharT = char, _Traits = std::char_traits<char>, _Alloc =
std::allocator<char>]()'

Code:
...snipped...
What does it mean and how should I fix it? Thanks!!!!


I think the line of code is this:
for(;i<cleartext.end();i++)

What does

operator<( int, std::stding::iterator )

mean ?

Perhaps you mean
for(;i<cleartext.length();i++)

I didn't go thorugh all that code, but from the error snippet it appears
you're trying to compare an integer with an iterator. Can't do that. i
would need to be an iterator itself.

OK, fixed that, here's the main program:

EnigmaMain.cpp
----------------------------------
#include "Enigma.hpp"
#include <iostream>
#include <cstdlib>
using namespace std;

int main()
{
start:
string cleartext;
char R1,R2,R3,R4,R5,Ref;
cout << "Enter the rotor and reflector settings: ";
cin >> R1 >> R2 >> R3 >> R4 >> R5 >> Ref;
Enigma encrypter(R1,R2,R3,R4,R5,Ref);
cin.ignore(1);
cout << "Enter cleartext: " << endl;
getline(cin,cleartext);
string ciphertext(encrypter.Encrypt(cleartext));
cout << "Ciphertext: " << ciphertext << endl;
goto start;
system("PAUSE");
return EXIT_SUCCESS;
}

It compiles and links just fine, but why won't the ciphertext appear?

OK, I still haven't solved the last problem of the ciphertext not
appearing, but now I have a new one. It keeps saying that
Rotor::CharacterMap() is multipley defined; I've got inclusion guards
by using #pragma once; what gives?

Code:
Enigma.hpp
--------------------------------------
#pragma once
#include <string>
using namespace std;

class Rotor
{
public:
Rotor(char pos=0):CurPos(0),steps(0)
{
memcpy(Alphabet,"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",36);
SetRotorPosition(CharacterMap(pos));
}
int GetSteps(){return steps;}
int CharacterMap(char Char);
void SetRotorPosition(int NewPos)
{
while(NewPos < 0)
{
NewPos +=36;
}
CurPos = NewPos%36;
}
void AdvanceRotor(int Steps)
{
CurPos += Steps;
while(CurPos < 0)
{
CurPos +=36;
}
CurPos %=36;
steps++;
}
void ReverseRotor(int Steps)
{
AdvanceRotor(-Steps);
steps--;
}
char GetCurrentCharacter()
{
return Alphabet[CurPos];
}
char GetCharacterIndex(int Index)
{
return Alphabet[(CurPos+Index)%36];
}
private:
char Alphabet[36];
int CurPos;
int steps;
};
class Enigma
{
public:
Enigma(char r1,char r2,char r3,char r4,char r5,char ref):
R1(r1),R2(r2),R3(r3),R4(r4),R5(r5),Ref(ref){}
~Enigma(){}
string Encrypt(const string& cleartext);
char plugboard(char Char);
private:
Rotor R1;
Rotor R2;
Rotor R3;
Rotor R4;
Rotor R5;
Rotor Ref;
};

Enigma.cpp
--------------------------------
#pragma once
#include "Enigma.hpp"
#include <string>
using namespace std;
int Rotor::CharacterMap(char Char)
{
if(Char=='A')
return 0;
else if(Char=='B')
return 1;
else if(Char=='C')
return 2;
else if(Char=='D')
return 3;
else if(Char=='E')
return 5;
else if(Char=='F')
return 6;
else if(Char=='G')
return 7;
else if(Char=='H')
return 8;
else if(Char=='I')
return 9;
else if(Char=='J')
return 10;
else if(Char=='K')
return 11;
else if(Char=='L')
return 12;
else if(Char=='M')
return 13;
else if(Char=='N')
return 14;
else if(Char=='O')
return 15;
else if(Char=='P')
return 16;
else if(Char=='Q')
return 17;
else if(Char=='R')
return 18;
else if(Char=='S')
return 19;
else if(Char=='T')
return 20;
else if(Char=='U')
return 21;
else if(Char=='V')
return 22;
else if(Char=='W')
return 23;
else if(Char=='X')
return 24;
else if(Char=='Y')
return 25;
else if(Char=='Z')
return 26;
else if(Char=='0')
return 27;
else if(Char=='1')
return 28;
else if(Char=='2')
return 29;
else if(Char=='3')
return 30;
else if(Char=='4')
return 31;
else if(Char=='5')
return 32;
else if(Char=='6')
return 33;
else if(Char=='7')
return 34;
else if(Char=='8')
return 35;
else if(Char=='9')
return 36;
}
char Enigma::plugboard(char Char)
{
if(Char=='A')
return 'A';
else if(Char=='B')
return 'Q';
else if(Char=='C')
return 'W';
else if(Char=='D')
return 'E';
else if(Char=='E')
return 'D';
else if(Char=='F')
return 'T';
else if(Char=='G')
return 'Y';
else if(Char=='H')
return 'U';
else if(Char=='I')
return 'I';
else if(Char=='J')
return 'O';
else if(Char=='K')
return 'P';
else if(Char=='L')
return 'S';
else if(Char=='M')
return 'M';
else if(Char=='N')
return 'N';
else if(Char=='O')
return 'J';
else if(Char=='P')
return 'K';
else if(Char=='Q')
return 'B';
else if(Char=='R')
return 'Z';
else if(Char=='S')
return 'L';
else if(Char=='T')
return 'F';
else if(Char=='U')
return 'H';
else if(Char=='V')
return 'X';
else if(Char=='W')
return 'C';
else if(Char=='X')
return 'V';
else if(Char=='Y')
return 'G';
else if(Char=='Z')
return 'R';
else if(Char=='0')
return '9';
else if(Char=='1')
return '8';
else if(Char=='2')
return '7';
else if(Char=='3')
return '6';
else if(Char=='4')
return '5';
else if(Char=='5')
return '4';
else if(Char=='6')
return '3';
else if(Char=='7')
return '2';
else if(Char=='8')
return '1';
else if(Char=='9')
return '0';
}

string Enigma::Encrypt(const string& cleartext)
{
string ciphertext;
ciphertext.resize(cleartext.size());
int i=0;
for(;i>cleartext.length();i++)
{
int val=Rotor().CharacterMap(cleartext);
char val1=R1.GetCharacterIndex(val);
R1.AdvanceRotor(i+1);
int val2=Rotor().CharacterMap(val1);
char val3=R2.GetCharacterIndex(val2);
if(R1.GetSteps()==36)
R2.ReverseRotor(i+1);
int val4=Rotor().CharacterMap(val3);
char val5=R3.GetCharacterIndex(val4);
if(R2.GetSteps()==-36)
R3.AdvanceRotor(i+1);
int val6=Rotor().CharacterMap(val5);
char val7=R4.GetCharacterIndex(val6);
if(R3.GetSteps()==36)
R4.ReverseRotor(i+1);
int val8=Rotor().CharacterMap(val7);
char val9=R5.GetCharacterIndex(val8);
if(R4.GetSteps()==-36)
R5.AdvanceRotor(i+1);
int val10=Rotor().CharacterMap(val9);
char val11=Ref.GetCharacterIndex(val10);
if(R5.GetSteps()==36)
Ref.ReverseRotor(1);
int val12=Rotor().CharacterMap(val11);
char val13=R5.GetCharacterIndex(val12);
int val14=Rotor().CharacterMap(val13);
char val15=R4.GetCharacterIndex(val14);
int val16=Rotor().CharacterMap(val15);
char val17=R3.GetCharacterIndex(val16);
int val18=Rotor().CharacterMap(val17);
char val19=R2.GetCharacterIndex(val18);
int val20=Rotor().CharacterMap(val19);
char val21=R1.GetCharacterIndex(val20);
ciphertext=plugboard(val21);
}
return ciphertext;
}

I can't figure it out.
 
S

summer7

Maybe '#pragma once' is not support by every compiler, I always use
#ifndef GUARD_THEFILENAME_H
#define GUARD_THEFILENAME_H
codes...
#endif
to protect the header file.
You may test it.
Or you could examine you precompile options of your compiler for a
resolution.

"Protoman дµÀ£º
"
Protoman said:
Jim said:
Protoman wrote:
I'm getting an error:

10 C:\Dev-Cpp\Enigma.cpp no match for 'operator<' in 'i <
(+cleartext)->std::basic_string<_CharT, _Traits, _Alloc>::end [with
_CharT = char, _Traits = std::char_traits<char>, _Alloc =
std::allocator<char>]()'

Code:
...snipped...
What does it mean and how should I fix it? Thanks!!!!


I think the line of code is this:
for(;i<cleartext.end();i++)

What does

operator<( int, std::stding::iterator )

mean ?

Perhaps you mean
for(;i<cleartext.length();i++)

I didn't go thorugh all that code, but from the error snippet it appears
you're trying to compare an integer with an iterator. Can't do that. i
would need to be an iterator itself.

OK, fixed that, here's the main program:

EnigmaMain.cpp
----------------------------------
#include "Enigma.hpp"
#include <iostream>
#include <cstdlib>
using namespace std;

int main()
{
start:
string cleartext;
char R1,R2,R3,R4,R5,Ref;
cout << "Enter the rotor and reflector settings: ";
cin >> R1 >> R2 >> R3 >> R4 >> R5 >> Ref;
Enigma encrypter(R1,R2,R3,R4,R5,Ref);
cin.ignore(1);
cout << "Enter cleartext: " << endl;
getline(cin,cleartext);
string ciphertext(encrypter.Encrypt(cleartext));
cout << "Ciphertext: " << ciphertext << endl;
goto start;
system("PAUSE");
return EXIT_SUCCESS;
}

It compiles and links just fine, but why won't the ciphertext appear?

OK, I still haven't solved the last problem of the ciphertext not
appearing, but now I have a new one. It keeps saying that
Rotor::CharacterMap() is multipley defined; I've got inclusion guards
by using #pragma once; what gives?

Code:
Enigma.hpp
--------------------------------------
#pragma once
#include <string>
using namespace std;

class Rotor
{
public:
Rotor(char pos=0):CurPos(0),steps(0)
{
memcpy(Alphabet,"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",36);
SetRotorPosition(CharacterMap(pos));
}
int GetSteps(){return steps;}
int CharacterMap(char Char);
void SetRotorPosition(int NewPos)
{
while(NewPos < 0)
{
NewPos +=36;
}
CurPos = NewPos%36;
}
void AdvanceRotor(int Steps)
{
CurPos += Steps;
while(CurPos < 0)
{
CurPos +=36;
}
CurPos %=36;
steps++;
}
void ReverseRotor(int Steps)
{
AdvanceRotor(-Steps);
steps--;
}
char GetCurrentCharacter()
{
return Alphabet[CurPos];
}
char GetCharacterIndex(int Index)
{
return Alphabet[(CurPos+Index)%36];
}
private:
char Alphabet[36];
int CurPos;
int steps;
};
class Enigma
{
public:
Enigma(char r1,char r2,char r3,char r4,char r5,char ref):
R1(r1),R2(r2),R3(r3),R4(r4),R5(r5),Ref(ref){}
~Enigma(){}
string Encrypt(const string& cleartext);
char plugboard(char Char);
private:
Rotor R1;
Rotor R2;
Rotor R3;
Rotor R4;
Rotor R5;
Rotor Ref;
};

Enigma.cpp
--------------------------------
#pragma once
#include "Enigma.hpp"
#include <string>
using namespace std;
int Rotor::CharacterMap(char Char)
{
if(Char=='A')
return 0;
else if(Char=='B')
return 1;
else if(Char=='C')
return 2;
else if(Char=='D')
return 3;
else if(Char=='E')
return 5;
else if(Char=='F')
return 6;
else if(Char=='G')
return 7;
else if(Char=='H')
return 8;
else if(Char=='I')
return 9;
else if(Char=='J')
return 10;
else if(Char=='K')
return 11;
else if(Char=='L')
return 12;
else if(Char=='M')
return 13;
else if(Char=='N')
return 14;
else if(Char=='O')
return 15;
else if(Char=='P')
return 16;
else if(Char=='Q')
return 17;
else if(Char=='R')
return 18;
else if(Char=='S')
return 19;
else if(Char=='T')
return 20;
else if(Char=='U')
return 21;
else if(Char=='V')
return 22;
else if(Char=='W')
return 23;
else if(Char=='X')
return 24;
else if(Char=='Y')
return 25;
else if(Char=='Z')
return 26;
else if(Char=='0')
return 27;
else if(Char=='1')
return 28;
else if(Char=='2')
return 29;
else if(Char=='3')
return 30;
else if(Char=='4')
return 31;
else if(Char=='5')
return 32;
else if(Char=='6')
return 33;
else if(Char=='7')
return 34;
else if(Char=='8')
return 35;
else if(Char=='9')
return 36;
}
char Enigma::plugboard(char Char)
{
if(Char=='A')
return 'A';
else if(Char=='B')
return 'Q';
else if(Char=='C')
return 'W';
else if(Char=='D')
return 'E';
else if(Char=='E')
return 'D';
else if(Char=='F')
return 'T';
else if(Char=='G')
return 'Y';
else if(Char=='H')
return 'U';
else if(Char=='I')
return 'I';
else if(Char=='J')
return 'O';
else if(Char=='K')
return 'P';
else if(Char=='L')
return 'S';
else if(Char=='M')
return 'M';
else if(Char=='N')
return 'N';
else if(Char=='O')
return 'J';
else if(Char=='P')
return 'K';
else if(Char=='Q')
return 'B';
else if(Char=='R')
return 'Z';
else if(Char=='S')
return 'L';
else if(Char=='T')
return 'F';
else if(Char=='U')
return 'H';
else if(Char=='V')
return 'X';
else if(Char=='W')
return 'C';
else if(Char=='X')
return 'V';
else if(Char=='Y')
return 'G';
else if(Char=='Z')
return 'R';
else if(Char=='0')
return '9';
else if(Char=='1')
return '8';
else if(Char=='2')
return '7';
else if(Char=='3')
return '6';
else if(Char=='4')
return '5';
else if(Char=='5')
return '4';
else if(Char=='6')
return '3';
else if(Char=='7')
return '2';
else if(Char=='8')
return '1';
else if(Char=='9')
return '0';
}

string Enigma::Encrypt(const string& cleartext)
{
string ciphertext;
ciphertext.resize(cleartext.size());
int i=0;
for(;i>cleartext.length();i++)
{
int val=Rotor().CharacterMap(cleartext);
char val1=R1.GetCharacterIndex(val);
R1.AdvanceRotor(i+1);
int val2=Rotor().CharacterMap(val1);
char val3=R2.GetCharacterIndex(val2);
if(R1.GetSteps()==36)
R2.ReverseRotor(i+1);
int val4=Rotor().CharacterMap(val3);
char val5=R3.GetCharacterIndex(val4);
if(R2.GetSteps()==-36)
R3.AdvanceRotor(i+1);
int val6=Rotor().CharacterMap(val5);
char val7=R4.GetCharacterIndex(val6);
if(R3.GetSteps()==36)
R4.ReverseRotor(i+1);
int val8=Rotor().CharacterMap(val7);
char val9=R5.GetCharacterIndex(val8);
if(R4.GetSteps()==-36)
R5.AdvanceRotor(i+1);
int val10=Rotor().CharacterMap(val9);
char val11=Ref.GetCharacterIndex(val10);
if(R5.GetSteps()==36)
Ref.ReverseRotor(1);
int val12=Rotor().CharacterMap(val11);
char val13=R5.GetCharacterIndex(val12);
int val14=Rotor().CharacterMap(val13);
char val15=R4.GetCharacterIndex(val14);
int val16=Rotor().CharacterMap(val15);
char val17=R3.GetCharacterIndex(val16);
int val18=Rotor().CharacterMap(val17);
char val19=R2.GetCharacterIndex(val18);
int val20=Rotor().CharacterMap(val19);
char val21=R1.GetCharacterIndex(val20);
ciphertext=plugboard(val21);
}
return ciphertext;
}

I can't figure it out.
 
P

Protoman

summer7 said:
Maybe '#pragma once' is not support by every compiler, I always use
#ifndef GUARD_THEFILENAME_H
#define GUARD_THEFILENAME_H
codes...
#endif
to protect the header file.
You may test it.
Or you could examine you precompile options of your compiler for a
resolution.

"Protoman дµÀ£º
"
Protoman said:
Jim Langston wrote:
Protoman wrote:
I'm getting an error:

10 C:\Dev-Cpp\Enigma.cpp no match for 'operator<' in 'i <
(+cleartext)->std::basic_string<_CharT, _Traits, _Alloc>::end [with
_CharT = char, _Traits = std::char_traits<char>, _Alloc =
std::allocator<char>]()'

Code:
...snipped...
What does it mean and how should I fix it? Thanks!!!!


I think the line of code is this:
for(;i<cleartext.end();i++)

What does

operator<( int, std::stding::iterator )

mean ?

Perhaps you mean
for(;i<cleartext.length();i++)

I didn't go thorugh all that code, but from the error snippet it appears
you're trying to compare an integer with an iterator. Can't do that. i
would need to be an iterator itself.

OK, fixed that, here's the main program:

EnigmaMain.cpp
----------------------------------
#include "Enigma.hpp"
#include <iostream>
#include <cstdlib>
using namespace std;

int main()
{
start:
string cleartext;
char R1,R2,R3,R4,R5,Ref;
cout << "Enter the rotor and reflector settings: ";
cin >> R1 >> R2 >> R3 >> R4 >> R5 >> Ref;
Enigma encrypter(R1,R2,R3,R4,R5,Ref);
cin.ignore(1);
cout << "Enter cleartext: " << endl;
getline(cin,cleartext);
string ciphertext(encrypter.Encrypt(cleartext));
cout << "Ciphertext: " << ciphertext << endl;
goto start;
system("PAUSE");
return EXIT_SUCCESS;
}

It compiles and links just fine, but why won't the ciphertext appear?

OK, I still haven't solved the last problem of the ciphertext not
appearing, but now I have a new one. It keeps saying that
Rotor::CharacterMap() is multipley defined; I've got inclusion guards
by using #pragma once; what gives?

Code:
Enigma.hpp
--------------------------------------
#pragma once
#include <string>
using namespace std;

class Rotor
{
public:
Rotor(char pos=0):CurPos(0),steps(0)
{
memcpy(Alphabet,"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",36);
SetRotorPosition(CharacterMap(pos));
}
int GetSteps(){return steps;}
int CharacterMap(char Char);
void SetRotorPosition(int NewPos)
{
while(NewPos < 0)
{
NewPos +=36;
}
CurPos = NewPos%36;
}
void AdvanceRotor(int Steps)
{
CurPos += Steps;
while(CurPos < 0)
{
CurPos +=36;
}
CurPos %=36;
steps++;
}
void ReverseRotor(int Steps)
{
AdvanceRotor(-Steps);
steps--;
}
char GetCurrentCharacter()
{
return Alphabet[CurPos];
}
char GetCharacterIndex(int Index)
{
return Alphabet[(CurPos+Index)%36];
}
private:
char Alphabet[36];
int CurPos;
int steps;
};
class Enigma
{
public:
Enigma(char r1,char r2,char r3,char r4,char r5,char ref):
R1(r1),R2(r2),R3(r3),R4(r4),R5(r5),Ref(ref){}
~Enigma(){}
string Encrypt(const string& cleartext);
char plugboard(char Char);
private:
Rotor R1;
Rotor R2;
Rotor R3;
Rotor R4;
Rotor R5;
Rotor Ref;
};

Enigma.cpp
--------------------------------
#pragma once
#include "Enigma.hpp"
#include <string>
using namespace std;
int Rotor::CharacterMap(char Char)
{
if(Char=='A')
return 0;
else if(Char=='B')
return 1;
else if(Char=='C')
return 2;
else if(Char=='D')
return 3;
else if(Char=='E')
return 5;
else if(Char=='F')
return 6;
else if(Char=='G')
return 7;
else if(Char=='H')
return 8;
else if(Char=='I')
return 9;
else if(Char=='J')
return 10;
else if(Char=='K')
return 11;
else if(Char=='L')
return 12;
else if(Char=='M')
return 13;
else if(Char=='N')
return 14;
else if(Char=='O')
return 15;
else if(Char=='P')
return 16;
else if(Char=='Q')
return 17;
else if(Char=='R')
return 18;
else if(Char=='S')
return 19;
else if(Char=='T')
return 20;
else if(Char=='U')
return 21;
else if(Char=='V')
return 22;
else if(Char=='W')
return 23;
else if(Char=='X')
return 24;
else if(Char=='Y')
return 25;
else if(Char=='Z')
return 26;
else if(Char=='0')
return 27;
else if(Char=='1')
return 28;
else if(Char=='2')
return 29;
else if(Char=='3')
return 30;
else if(Char=='4')
return 31;
else if(Char=='5')
return 32;
else if(Char=='6')
return 33;
else if(Char=='7')
return 34;
else if(Char=='8')
return 35;
else if(Char=='9')
return 36;
}
char Enigma::plugboard(char Char)
{
if(Char=='A')
return 'A';
else if(Char=='B')
return 'Q';
else if(Char=='C')
return 'W';
else if(Char=='D')
return 'E';
else if(Char=='E')
return 'D';
else if(Char=='F')
return 'T';
else if(Char=='G')
return 'Y';
else if(Char=='H')
return 'U';
else if(Char=='I')
return 'I';
else if(Char=='J')
return 'O';
else if(Char=='K')
return 'P';
else if(Char=='L')
return 'S';
else if(Char=='M')
return 'M';
else if(Char=='N')
return 'N';
else if(Char=='O')
return 'J';
else if(Char=='P')
return 'K';
else if(Char=='Q')
return 'B';
else if(Char=='R')
return 'Z';
else if(Char=='S')
return 'L';
else if(Char=='T')
return 'F';
else if(Char=='U')
return 'H';
else if(Char=='V')
return 'X';
else if(Char=='W')
return 'C';
else if(Char=='X')
return 'V';
else if(Char=='Y')
return 'G';
else if(Char=='Z')
return 'R';
else if(Char=='0')
return '9';
else if(Char=='1')
return '8';
else if(Char=='2')
return '7';
else if(Char=='3')
return '6';
else if(Char=='4')
return '5';
else if(Char=='5')
return '4';
else if(Char=='6')
return '3';
else if(Char=='7')
return '2';
else if(Char=='8')
return '1';
else if(Char=='9')
return '0';
}

string Enigma::Encrypt(const string& cleartext)
{
string ciphertext;
ciphertext.resize(cleartext.size());
int i=0;
for(;i>cleartext.length();i++)
{
int val=Rotor().CharacterMap(cleartext);
char val1=R1.GetCharacterIndex(val);
R1.AdvanceRotor(i+1);
int val2=Rotor().CharacterMap(val1);
char val3=R2.GetCharacterIndex(val2);
if(R1.GetSteps()==36)
R2.ReverseRotor(i+1);
int val4=Rotor().CharacterMap(val3);
char val5=R3.GetCharacterIndex(val4);
if(R2.GetSteps()==-36)
R3.AdvanceRotor(i+1);
int val6=Rotor().CharacterMap(val5);
char val7=R4.GetCharacterIndex(val6);
if(R3.GetSteps()==36)
R4.ReverseRotor(i+1);
int val8=Rotor().CharacterMap(val7);
char val9=R5.GetCharacterIndex(val8);
if(R4.GetSteps()==-36)
R5.AdvanceRotor(i+1);
int val10=Rotor().CharacterMap(val9);
char val11=Ref.GetCharacterIndex(val10);
if(R5.GetSteps()==36)
Ref.ReverseRotor(1);
int val12=Rotor().CharacterMap(val11);
char val13=R5.GetCharacterIndex(val12);
int val14=Rotor().CharacterMap(val13);
char val15=R4.GetCharacterIndex(val14);
int val16=Rotor().CharacterMap(val15);
char val17=R3.GetCharacterIndex(val16);
int val18=Rotor().CharacterMap(val17);
char val19=R2.GetCharacterIndex(val18);
int val20=Rotor().CharacterMap(val19);
char val21=R1.GetCharacterIndex(val20);
ciphertext=plugboard(val21);
}
return ciphertext;
}

I can't figure it out.


OK, but it still says it's multiply defined. And no one has told me why
the ciphertext doesn't appear!
 
P

Protoman

Protoman said:
summer7 said:
Maybe '#pragma once' is not support by every compiler, I always use
#ifndef GUARD_THEFILENAME_H
#define GUARD_THEFILENAME_H
codes...
#endif
to protect the header file.
You may test it.
Or you could examine you precompile options of your compiler for a
resolution.

"Protoman дµÀ£º
"
Protoman wrote:
Jim Langston wrote:
Protoman wrote:
I'm getting an error:

10 C:\Dev-Cpp\Enigma.cpp no match for 'operator<' in 'i <
(+cleartext)->std::basic_string<_CharT, _Traits, _Alloc>::end [with
_CharT = char, _Traits = std::char_traits<char>, _Alloc =
std::allocator<char>]()'

Code:
...snipped...
What does it mean and how should I fix it? Thanks!!!!


I think the line of code is this:
for(;i<cleartext.end();i++)

What does

operator<( int, std::stding::iterator )

mean ?

Perhaps you mean
for(;i<cleartext.length();i++)

I didn't go thorugh all that code, but from the error snippet it appears
you're trying to compare an integer with an iterator. Can't do that. i
would need to be an iterator itself.

OK, fixed that, here's the main program:

EnigmaMain.cpp
----------------------------------
#include "Enigma.hpp"
#include <iostream>
#include <cstdlib>
using namespace std;

int main()
{
start:
string cleartext;
char R1,R2,R3,R4,R5,Ref;
cout << "Enter the rotor and reflector settings: ";
cin >> R1 >> R2 >> R3 >> R4 >> R5 >> Ref;
Enigma encrypter(R1,R2,R3,R4,R5,Ref);
cin.ignore(1);
cout << "Enter cleartext: " << endl;
getline(cin,cleartext);
string ciphertext(encrypter.Encrypt(cleartext));
cout << "Ciphertext: " << ciphertext << endl;
goto start;
system("PAUSE");
return EXIT_SUCCESS;
}

It compiles and links just fine, but why won't the ciphertext appear?

OK, I still haven't solved the last problem of the ciphertext not
appearing, but now I have a new one. It keeps saying that
Rotor::CharacterMap() is multipley defined; I've got inclusion guards
by using #pragma once; what gives?

Code:
Enigma.hpp
--------------------------------------
#pragma once
#include <string>
using namespace std;

class Rotor
{
public:
Rotor(char pos=0):CurPos(0),steps(0)
{
memcpy(Alphabet,"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",36);
SetRotorPosition(CharacterMap(pos));
}
int GetSteps(){return steps;}
int CharacterMap(char Char);
void SetRotorPosition(int NewPos)
{
while(NewPos < 0)
{
NewPos +=36;
}
CurPos = NewPos%36;
}
void AdvanceRotor(int Steps)
{
CurPos += Steps;
while(CurPos < 0)
{
CurPos +=36;
}
CurPos %=36;
steps++;
}
void ReverseRotor(int Steps)
{
AdvanceRotor(-Steps);
steps--;
}
char GetCurrentCharacter()
{
return Alphabet[CurPos];
}
char GetCharacterIndex(int Index)
{
return Alphabet[(CurPos+Index)%36];
}
private:
char Alphabet[36];
int CurPos;
int steps;
};
class Enigma
{
public:
Enigma(char r1,char r2,char r3,char r4,char r5,char ref):
R1(r1),R2(r2),R3(r3),R4(r4),R5(r5),Ref(ref){}
~Enigma(){}
string Encrypt(const string& cleartext);
char plugboard(char Char);
private:
Rotor R1;
Rotor R2;
Rotor R3;
Rotor R4;
Rotor R5;
Rotor Ref;
};

Enigma.cpp
--------------------------------
#pragma once
#include "Enigma.hpp"
#include <string>
using namespace std;
int Rotor::CharacterMap(char Char)
{
if(Char=='A')
return 0;
else if(Char=='B')
return 1;
else if(Char=='C')
return 2;
else if(Char=='D')
return 3;
else if(Char=='E')
return 5;
else if(Char=='F')
return 6;
else if(Char=='G')
return 7;
else if(Char=='H')
return 8;
else if(Char=='I')
return 9;
else if(Char=='J')
return 10;
else if(Char=='K')
return 11;
else if(Char=='L')
return 12;
else if(Char=='M')
return 13;
else if(Char=='N')
return 14;
else if(Char=='O')
return 15;
else if(Char=='P')
return 16;
else if(Char=='Q')
return 17;
else if(Char=='R')
return 18;
else if(Char=='S')
return 19;
else if(Char=='T')
return 20;
else if(Char=='U')
return 21;
else if(Char=='V')
return 22;
else if(Char=='W')
return 23;
else if(Char=='X')
return 24;
else if(Char=='Y')
return 25;
else if(Char=='Z')
return 26;
else if(Char=='0')
return 27;
else if(Char=='1')
return 28;
else if(Char=='2')
return 29;
else if(Char=='3')
return 30;
else if(Char=='4')
return 31;
else if(Char=='5')
return 32;
else if(Char=='6')
return 33;
else if(Char=='7')
return 34;
else if(Char=='8')
return 35;
else if(Char=='9')
return 36;
}
char Enigma::plugboard(char Char)
{
if(Char=='A')
return 'A';
else if(Char=='B')
return 'Q';
else if(Char=='C')
return 'W';
else if(Char=='D')
return 'E';
else if(Char=='E')
return 'D';
else if(Char=='F')
return 'T';
else if(Char=='G')
return 'Y';
else if(Char=='H')
return 'U';
else if(Char=='I')
return 'I';
else if(Char=='J')
return 'O';
else if(Char=='K')
return 'P';
else if(Char=='L')
return 'S';
else if(Char=='M')
return 'M';
else if(Char=='N')
return 'N';
else if(Char=='O')
return 'J';
else if(Char=='P')
return 'K';
else if(Char=='Q')
return 'B';
else if(Char=='R')
return 'Z';
else if(Char=='S')
return 'L';
else if(Char=='T')
return 'F';
else if(Char=='U')
return 'H';
else if(Char=='V')
return 'X';
else if(Char=='W')
return 'C';
else if(Char=='X')
return 'V';
else if(Char=='Y')
return 'G';
else if(Char=='Z')
return 'R';
else if(Char=='0')
return '9';
else if(Char=='1')
return '8';
else if(Char=='2')
return '7';
else if(Char=='3')
return '6';
else if(Char=='4')
return '5';
else if(Char=='5')
return '4';
else if(Char=='6')
return '3';
else if(Char=='7')
return '2';
else if(Char=='8')
return '1';
else if(Char=='9')
return '0';
}

string Enigma::Encrypt(const string& cleartext)
{
string ciphertext;
ciphertext.resize(cleartext.size());
int i=0;
for(;i>cleartext.length();i++)
{
int val=Rotor().CharacterMap(cleartext);
char val1=R1.GetCharacterIndex(val);
R1.AdvanceRotor(i+1);
int val2=Rotor().CharacterMap(val1);
char val3=R2.GetCharacterIndex(val2);
if(R1.GetSteps()==36)
R2.ReverseRotor(i+1);
int val4=Rotor().CharacterMap(val3);
char val5=R3.GetCharacterIndex(val4);
if(R2.GetSteps()==-36)
R3.AdvanceRotor(i+1);
int val6=Rotor().CharacterMap(val5);
char val7=R4.GetCharacterIndex(val6);
if(R3.GetSteps()==36)
R4.ReverseRotor(i+1);
int val8=Rotor().CharacterMap(val7);
char val9=R5.GetCharacterIndex(val8);
if(R4.GetSteps()==-36)
R5.AdvanceRotor(i+1);
int val10=Rotor().CharacterMap(val9);
char val11=Ref.GetCharacterIndex(val10);
if(R5.GetSteps()==36)
Ref.ReverseRotor(1);
int val12=Rotor().CharacterMap(val11);
char val13=R5.GetCharacterIndex(val12);
int val14=Rotor().CharacterMap(val13);
char val15=R4.GetCharacterIndex(val14);
int val16=Rotor().CharacterMap(val15);
char val17=R3.GetCharacterIndex(val16);
int val18=Rotor().CharacterMap(val17);
char val19=R2.GetCharacterIndex(val18);
int val20=Rotor().CharacterMap(val19);
char val21=R1.GetCharacterIndex(val20);
ciphertext=plugboard(val21);
}
return ciphertext;
}

I can't figure it out.


OK, but it still says it's multiply defined. And no one has told me why
the ciphertext doesn't appear!


OK, I fixed the multiple def problem by rebuilding instead of merely
recompiling, but I still haven't fixed the ciphertext not appearing
problem.
 
N

Nikolaos D. Bougalis

Protoman didn't trip, and gave us another 400 line message saying:
OK, I fixed the multiple def problem by rebuilding instead of merely
recompiling, but I still haven't fixed the ciphertext not appearing
problem.

Perhaps it has something to do with your loop:
int i=0;
for(;i>cleartext.length();i++)

Also, you use the construct "Rotor().CharacterMap(val17)" all over your code.
Do you understand what typing "Rotor()" does?

-n
 
P

Protoman

Nikolaos said:
Protoman didn't trip, and gave us another 400 line message saying:


Perhaps it has something to do with your loop:


Also, you use the construct "Rotor().CharacterMap(val17)" all over your code.
Do you understand what typing "Rotor()" does?

-n

Yeah, it creates an anon Rotor object, why?
 
?

=?ISO-8859-1?Q?Erik_Wikstr=F6m?=

If you have no use of i after the loop exits it would be much nicer to
use 'for(int i = 0; i > cleartext.lenght(); ++i)'.
Yeah, it creates an anon Rotor object, why?

It would be much better to make the CharacterMap()-function static so
you can call Rotor::CharacterMap(val17), this way you don't create a new
instance of the class all the time.
 
N

Nikolaos D. Bougalis

Erik said:
If you have no use of i after the loop exits it would be much nicer to
use 'for(int i = 0; i > cleartext.lenght(); ++i)'.

Of course, that would still not solve his problem. That loop iterates exactly
ZERO times.

-n
 
N

Nikolaos D. Bougalis

Protoman said:
Yeah, it creates an anon Rotor object, why?

Just making sure. A lot of people don't realize that "Rotor()" actually
results in the creation of a temporary object and that each Rotor object is
unique and independent.

And, design wise, it's unnecessary. You're better off making CharacterMap a
static member function of Rotor as Erik Wikström suggested.

-n
 
P

Protoman

Nikolaos said:
Just making sure. A lot of people don't realize that "Rotor()" actually
results in the creation of a temporary object and that each Rotor object is
unique and independent.

And, design wise, it's unnecessary. You're better off making CharacterMap a
static member function of Rotor as Erik Wikström suggested.

-n

OK, I can see the ciphertext now. What would be the Decrypt() fn?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top