Question: in this code when i input this line - this IS a TEST the code outputs - invalid input. how to fix that? vector plainText()

in this code when i input this line -

this IS a TEST

the code outputs - invalid input. how to fix that?

vector plainText()

{

string textMessage = "";

vector plainTextVector;

while (true)

{

cout << "Enter a plain text to be encoded" << endl;

getline(cin, textMessage);

bool validInput = true;

for (int i = 0; i < textMessage.length(); i++)

{

if (!isalpha(textMessage[i]))

{

validInput = false;

cout << "Invalid Input" << endl;

break;

}

}

if (validInput)

{

for (int i = 0; i < textMessage.length(); i++)

{

plainTextVector.push_back(textMessage[i]);

}

return plainTextVector;

}

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!