将值传递到数组/数组中的值丢失时出错

我有一个文本文件,并将其传递给char数组。当我在getline()循环中显示时很好,但是经过加密之后,仅最后一行被加密并显示。我试图在输入shift键之前在数组中显示值,并且数组中的内容仅是文本的最后一行。出了什么问题?请帮忙!!

char msg[5000];
string plaintext;
int choice, shift;
char ch;

// Read file into char array
ifstream infile("plaintext.txt");
while (getline(infile, plaintext))
{
    strcpy_s(msg, plaintext.c_str());
    for (int i = 0; i < plaintext.length(); i++)
    {
        cout << msg[i];
    }
}

cout << endl;
cout << "Enter shift key: ";
cin >> shift;                           //take the shift as input
cout << "Enter your choice" << endl;
cout << "1.Encryption" << endl;
cout << "2.Decryption" << endl;
cin >> choice;

// Encryption
if (choice == 1)
{
    for (int i = 0; msg[i] != '\0'; i++) {
        ch = msg[i];
        //encrypt for lowercase letter
        if(ch >= 'a' && ch <= 'z') {
            ch = ch + shift;
            if (ch > 'z') {
                ch = ch - 'z' + 'a' - 1;
            }
            msg[i] = ch;
        }
        //encrypt for uppercase letter
        else if (ch >= 'A' && ch <= 'Z') {
            ch = ch + shift;
            if (ch > 'Z') {
                ch = ch - 'Z' + 'A' - 1;
            }
            msg[i] = ch;
        }
    }
    printf("Encrypted message: %s", msg);

}

结果

enter image description here