C++ String Array Input Guide

In C++, you can use std::cin to input an array of strings. Here is a simple example code that inputs a string array and prints it out:

#include <iostream>
#include <string>

int main() {
    const int SIZE = 5;
    std::string arr[SIZE];

    // 输入字符串数组
    for (int i = 0; i < SIZE; i++) {
        std::cout << "Enter string " << i+1 << ": ";
        std::cin >> arr[i];
    }

    // 打印字符串数组
    std::cout << "You entered the following strings:" << std::endl;
    for (int i = 0; i < SIZE; i++) {
        std::cout << arr[i] << std::endl;
    }

    return 0;
}

In this example, we started by defining a string array called arr with a size of 5. Next, we used std::cin to input 5 strings which were stored in the array. Finally, we printed out the inputted string array.

bannerAds