Hi,
I have some simple code shown below, saved into a file (let us say stock_portfolio.cxx).
I am trying to compile this as:
g++ stock_portfolio.cxx
error: scalar object 'v' requires one element in initializer
The gcc version I have is:
gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-52)
#include<iostream>
#include<vector>
int main() {
std::vector<int>v = {1,2,3,4,5,6};
//std::vector<string> four_star_stocks;
for(int i = 0; i < v.size(); ++i){
std::cout << "Stock S&P: " << v[i] << "\n";
}
std::cout << "========================" << "\n";
std::cout << "Totals : " << v.size() << "\n";
return 0;
}
list-initialization was only introduced to C++ in C++11. gcc version 4.1 doesn't support C++11 (see https://gcc.gnu.org/projects/cxx0x.html)
It's unclear to me if you're question is asking for a suggested solution/fix or an explanation of why your code will not compile.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With