Unicode characters

Hello everybody. I've got as homework the coding of Caesar's cipher in C++. I've created the following code. It turns out that the following letters do not work ç, ë, Ë and Ç . Does anyone have any idea?

#include <iostream>
#include <string>
using namespace std;
int main()
{
string alphabet= "abcçdeëfghijklmno pqrstuvxyzwABCÇDEËFGHIJKLMNOPQRSTUVXYZW!#$%&'()*+,-./0123456789:;<=>?@[]_{|~}`";
int code[ alphabet.length() ];
for( int j = 0; j < alphabet.length(); j++ )
code[ j ] = j;
cout << "Hello. You can cipher your messages through the following alphabet\n";

for( int c = 0; c < alphabet.length(); c++ )
cout << alphabet[ c ] << ' ';
int continue;
cout << "\nType a number to continue. Press -1 to end: ";
cin >> continue;

while( continue!= -1 )
{
string text;
cout << "Input a message: ";
getline( cin>>ws, text);
string cipher;

int key;
cout << "Input key: ";
cin >> key;
int counter = 0;
for( int i = 0; i < text.length(); i++ )
{
for( int k = 0; k < alphabet.length(); k++ )
{

if( text[ i ] == alphabet[ k ] )
{

cipher += alphabet[ (code[ k ] + key ) % alphabet.length()];
counter++;
}
}
}
if (counter == text.length() )
{
cout << "The cipher text is: " << cipher;
}
else
cout << "The preceding text cannot be ciphered" << endl;
cout << "\nType a number to continue. Press -1 to end: ";
cin >> continue;
}
}
I'd guess that the console code page is different from the code page you store the string in
That means??
That means that the character ç, ë, Ë and Ç from the console is different from your alphabet.

You store your source code in a certain character set which is likely not the console character set

What IDE do you use? What os?

And please use code tags: [code]Your code[/code]
Read this: http://www.cplusplus.com/articles/z13hAqkS/
It could also be that the encoding that is being used needs 2 chars to store ç, ë, Ë, etc. This is the case with UTF-8.
I think you need to use wstring instead of string. ç, ë, and Ë require multiple bytes to store.
Topic archived. No new replies allowed.