我需要做的就是将您的全名的输入字符串解析为 3 个单独的名称,这样我就可以获取每个名称的首字母并打印它们。谁能指出我正确的方向?
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
int main()
{
string [parsed_output] = fullName.split(" ");
string firstName = parsed_output[0];
string middleName = parsed_ouput[1];
string lastName = parsed_output[2];
string fullName;
char firstLetter = firstName[0];
char middleLetter = middleName[0];
char lastLetter = lastName[0];
cout << "Enter your first name, middle name or initial, and last name separated by spaces: \n";
cin >> fullName;
cout << "Your initials are: " << firstLetter << middleLetter << lastLetter << '\n';
cout << "Your name is: " << firstName << " " << middleName << " " << lastName << '\n';
return 0;
}