-
inputing a string
Hi all, I am having a problem with strings input.
Code:
#include <iostream>
#include <string>
using namespace std;
main() {
string temp;
cin >> temp;
return 0;
}
and when i try to compile it in Watcom C/C++, it somehow returns:
cd D:\Cryptography
wmake -f D:\Cryptography\Tools.mk -h -e D:\Cryptography\Tools.exe
wpp386 main.cpp -i=C:\WATCOM\h;C:\WATCOM\h\nt -w4 -e25 -zq -od -d2 -6r -bt=nt -mf -xs -xr
main.cpp(25): Error! E157: col(13) left expression must be integral
main.cpp(25): Note! N717: col(13) left operand type is 'std::istream watcall (lvalue)'
main.cpp(25): Note! N718: col(13) right operand type is 'std::basic_string<char,std::char_traits<char>,std ::allocator<char>> (lvalue)'
Error(E42): Last command making (D:\Cryptography\main.obj) returned a bad status
Error(E02): Make execution terminated
Execution complete
-
Standard C++ requires functions to have an explicit return type:
-
thanks...but after i changed it, it still wont compile, giving me the same error code.
-
Somehow, it looks like what you've shown here and the error messages don't match exactly - the error seems to be on line 25, which is a bit more than the 10 or so lines that you show here. Can you either:
1. Post the actual code that gives the error.
2. Post the error code from compiling this code.
I'm basing this on:The number in brackets is usualy the line number.
--
Mats
-
ok... the whole code is
Code:
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int i, i1; // Loop variables
char * strcat ( char*, char const* );
class Key {
public:
char value; // The actual key for shrift keys
string code; // The key for other monoalpheric ciphers
int length; // The length of the key
char Shrift_Key[2][26]; // The entire key for a shrift cipher
Key(char choice) { // Constructor
string temp; // A temporary array
cout << "Enter the key." << endl;
cin >> temp; // and this is where the error is
if(!temp.length()) {
cout << "You must enter a key inorder to preceed." << endl;
return;
}
if(temp.length() == 1) {
if(choice == 1) {
if(temp[0] != (int) temp[0]) {
cout << "You must enter a number inorder to proceed." << endl;
return;
}
if(temp[0] <20) {
cout << "A re-arranging of this complex is not supported yet." << endl;
return;
}
}
else {
length = 1;
value = temp[0];
}
}
if(temp.length()>26) {
cout << "Decrypting with homophones is not avalible yet." << endl;
return;
}
else {
length = temp.length();
for(i=0;i<length;++i) code[i] = temp[i];
}
};
};
class Cipher {
public:
int length; // Length of array
string Text;
Cipher() { // Constructor
cout << "Enter the encrypted-text." << endl;
length = Text.length();
};
};
void SplitCode(char choice);
void Menu(void);
int main() {return 0;}
void Menu(void) {
char choice; // What to do
// starting the menu
cout << "Menu:" << endl;
cout << " 1. Sort the cipher text into shrift siphers according to the key length" << endl;
cout << " 2. Frequency analysis the cipher-text." << endl;
cout << " 3. Decrypt a monoalpheric cipher with a key." << endl;
cout << "Enter q to quit.\n" << endl;
cout << "Enter your choice: ";
cin >> choice;
switch(choice) {
case '1' :
SplitCode(choice);
Menu();
break;
case '2' :
Menu();
break;
case '3' :
Menu();
break;
case 'q' :
break;
default :
cout << "Please enter a valid choice." << endl;
Menu();
break;
}
}
void SplitCode(char choice) {
Cipher Vigenerec; // Create an instance of the cipher object
Key Vigenerek(choice); // Create an instance of the key
int Rmd = Vigenerek.value % Vigenerec.length;// The number of odd digits out (uncompleted bits of key)
int ArrayLen = (Vigenerec.length - Rmd) / Vigenerek.value;
if(Rmd) ArrayLen++;
vector<char> Split_Text[20];
for(i=0;i<Vigenerek.value;++i) Split_Text[i].resize(ArrayLen);
for(i=0;i<Vigenerec.length;++i) {
int r = i % 5; // The bit of the key
int r2 = (i-r)/5; // How many times did the key looped
Split_Text[r][r2] = Vigenerec.Text[i];
}
for(i=0;i<Vigenerek.value;++i) {
for(i1=0;i1<ArrayLen;i++) cout << Split_Text[i][i1];
cout << "" << endl;
}
}
and btw, it is not finished
-
That compiles fine with gcc mingw 3.4.2.
--
Mats