String vs Char

Discussion in 'C++' started by azygous420, Mar 12, 2007.

Thread Status:
Not open for further replies.
  1. azygous420

    azygous420 New Member

    Joined:
    Mar 10, 2007
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    Hello, I'm new here and need some help understanding the parameters of these two integer types. I recently started programming again and tried to make a hex encoder/decoder. I can't figure out how to make a program analyze two characters in a "char" variable.
    This is my program so far...
    Code:
    int main(int argc, char* argv[])
    {
            int code;
            int test;
            int n;
            test = 0;
            int maintest;
            maintest = 0;
            float word;
            char yn;
            n = 0;
    
            while (maintest == 0)
            {
            fstream file("decode.txt", ios::out);
            char ch, password[51];
            cout << "\nEnter a password (max 8 letters): ";
            cin >> password;
            file << password;
            file.close();
            file.open("decode.txt", ios::in);
            while (test != 1)
            {
                    cout << "\nHit 1 to Encode, Hit 2 to Decode: ";
                    cin >> code;
                    if (code == 1 || code == 2)
                    {
                            test = test++;
                    }
            }
            if (code == 1)
            {
                    file.get(ch);
                    while (!file.fail())
                    {
                            cout << hex << ch;
                            n = n++;
                            file.get(ch);
                    }
            }
            if (code == 2);
            {
    
            }
            cout << "\nFinish? (Y or N)";
            cin >> yn;
            switch (yn)
            {
                    case 'y': maintest = 1;
                    case 'n': break;
                    default : cout << "\nError";
            }
            }
            return 0;
    }
    It says it can't convert char to string. So I've tried to use strings instead of char. but i can't get it to input strings correctly. Any help would be greatly appreciated.
     
    Last edited by a moderator: Mar 12, 2007
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,336
    Likes Received:
    377
    Trophy Points:
    83
    Duplicate of [thread=3359]String vs Char[/thread]. Thread closed.
     
Thread Status:
Not open for further replies.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice