获取多行输入以在C++中解析

Getting Multiline Input for parsing in C++

本文关键字:C++ 输入 获取      更新时间:2023-10-16

我想创建一个程序,允许用户在控制台中键入多行输入,然后当他们按下某个键时,在这种情况下,它将是键F,输入将停止,所有内容都存储在名为inputstring中。

此字符串应包含用户输入的所有输入,包括空格、新行等。我希望它是一个字符串,稍后可以在程序中解析。

#include <iostream>
#include <vector>
using namespace std;
int main() {
 string input;
 while(cin >> input){
    // Code for exiting the loop when the key "K" is pressed should be put here.
 }

}
string input;
string line;
while (getline(cin, line))
{
    if (line == "Kn")
        break;
    input += line;
}