在向量中存储字符串组

时间:2019-01-25 05:20:11

标签: c++

我试图做的程序是将成串的字符串读成向量,但用'\ n'分隔。

示例输入:

AAAA
AAAA
AAAA  // store all A in a vector

BB
BB    // store all B in another vector

我不需要同时拥有两个向量。 我尝试了以下操作,但无法正确存储。

#include<bits/stdc++.h> 
using namespace std;

int main() {
    vector <string> board;
    string input;
    while(getline(cin, input, '\n')) 
        board.push_back(input);
    for (int i=0; i<board.size(); i++){
        printf("%s\n", board[i]);
        printf("----------\n");
    }  
}

0 个答案:

没有答案