Thread: inputing a string

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    32

    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

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    835
    Standard C++ requires functions to have an explicit return type:
    Code:
    int main() {

  3. #3
    Registered User
    Join Date
    Sep 2007
    Posts
    32
    thanks...but after i changed it, it still wont compile, giving me the same error code.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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:
    main.cpp(25): ...
    The number in brackets is usualy the line number.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Sep 2007
    Posts
    32
    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 &#37; 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
    Last edited by _lazycat_; 10-09-2007 at 11:04 PM.

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    That compiles fine with gcc mingw 3.4.2.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ ini file reader problems
    By guitarist809 in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2008, 06:02 AM
  2. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  3. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  4. creating class, and linking files
    By JCK in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2002, 02:45 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM