为什么数组不打印列表

Why array does not print list?

本文关键字:列表 打印 数组 为什么      更新时间:2023-10-16
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
    int i;
    char s[10] = {'a' , 'b' ,'c' 'd' ,'e', 'f', 'g', 'g','h','i'};
    cout << "element" << setw(7) << "value " << endl;
    for (i=0 ; i <10 ; i++)
    cout << i << setw(7) << s[i] << endl;
    return 0;
}

我想要 tp 获取列表,例如

element       value
0              a
1              b
2              c
3              d
4              e
5              f  
6              g
7              g
8              h
9              i

但是编译器给出了错误....有没有人可以指出我的错误?

初始值设定项列表中有一个拼写错误。您忘了放置逗号

char s[10] = {'a' , 'b' ,'c' 'd' ,'e', 'f', 'g', 'g','h','i'};
                          ^^^^