String vs Char

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

  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,375
    Likes Received:
    388
    Trophy Points:
    83
    Isnt the issue already in discussion [thread=3343]here[/thread].
     
  3. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    http://www.daweidesigns.com
    Seriously, fellow, replication of a thread doesn't increase attention, it dilutes it. Worse than that, it annoys people so that they decide not to help, anymore.
     
  4. azygous420

    azygous420 New Member

    Joined:
    Mar 10, 2007
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    sry it wasn't showing up so i made a bunch on accident
     

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