Я пытаюсь создать почтовое приложение командной строки для Linux (хотя я занимаюсь разработкой на XCode, потому что виртуальная машина потребляет много энергии для моего компьютера). У меня есть два варианта в главном меню (где пользователь вводит номер для выбора). Я использую это после каждого ввода, будь то простой can или get line (can, stringName):
void clearCin() {
cin.clear();
cin.ignore(INT_MAX, '\n');
}
Вот почему я озадачен тем, что получаю всевозможные странные действия со своим вводом. Вот мой код и пример вывода (конечная функция - это просто для l oop, которая стоит << endl;): </p>
Код
bool stdEmail() {
string to, cc, bcc, subject, message;
cout << "When entering email addresses, seperate multiple email addresses with a space";
endl(2);
cout << "To: ";
getline(cin, to);
clearCin();
cout << "cc: ";
getline(cin, cc);
clearCin();
cout << "bcc: ";
getline(cin, bcc);
clearCin();
endl(1);
cout << "Subject: ";
getline(cin, subject);
clearCin();
endl(1);
cout << "Now enter your message, when you're finished, type a period on a new line";
endl(2);
ofstream file;
file.open("newMessage.txt", fstream::trunc);
bool repeat = true;
while (repeat) {
getline(cin, message);
clearCin();
if (message == ".") {
repeat = false;
} else {
file << message << endl;
}
}
file.close();
return true;
}
Вывод
--------------------------------------------------
Welcome to mark's Multi-Mail program
Main menu:
--------------------------------------------------
1. Send personalized emails to multiple recipients
2. Send a standard email
3. Exit the program
--------------------------------------------------
2
When entering email addresses, seperate multiple email addresses with a space
To: one@example.com two@example.com
cc: three@example.com
bcc:
Subject: Thanks for your help!
Now enter your message, when you're finished, type a period on a new line
Here is a sample message
.
Now I am trying to get it out of taking the message which should have happened when I typed a .
.
Program ending Have a Nice Day
Program ended with exit code: 0
Вот что отображается в newMessage.txt:
Вот пример сообщения