C++ 大括号初始化变量

创建日期: 2024-05-28 16:13 | 作者: 风波 | 浏览次数: 14 | 分类: C++

来源:https://www.educative.io/answers/declaring-a-variable-with-braces-in-cpp

curly braces to initialize variables in C++

#include <iostream>
#include <vector>
using namespace std;

int main() {
  int a{20};
  cout << "The value of variable a is: "<< a << endl;

  string b{"This is a string"};
  cout << "The value of variable b is: "<< b << endl;

  std::vector<int> c{10, 5};
  cout<< "The values of variable c are: " << endl;
  for(int i=0; i<c.size(); i++){
    cout << c[i] << endl;
  }
}
14 浏览
9 爬虫
0 评论