10
我对C++非常陌生,并且在阅读我的错误时遇到了困难我能够消除其中的大部分错误,但是我只能解决一些错误,请求帮助。扩展初始化程序列表仅适用于
这里是程序
#include <string>
#include <iostream>
using namespace std;
int main(){
int *bN = new int[9];
string bankNum;
int *number = new int[9];
int total, remain;
int *multi = new int{7,3,9,7,3,9,7,3};
cout<<"Please enter the bank number located at the bottom of the check"<<endl;
cin>>bankNum;
for(int i = 0; i < 8; i++){
bN[i]= (bankNum[i]-48);
}
for(int i = 0; i < 8;i++){
cout<<bN[i];
}
cout<<endl;
for(int i = 0; i < 8;i++){
cout<<multi[i];
}
cout<<endl;
for(int i = 0; i < 8;i++){
bN[i] = bN[i] * multi[i];
cout<< bN[i];
}
cout<<endl;
for(int i = 0; i < 8;i++){
total += bN[i]
cout<<total;
}
cout<<endl;
remain = total % 10;
if(remain == (bankNum[9] - 48)){
cout<<"The Number is valad"<<endl;
cout<<remain<<endl;
}
}
和错误
[email protected]:~$ c++ bankNum.cpp
bankNum.cpp: In function âint main()â:
bankNum.cpp:9:19: warning: extended initializer lists only available with -std=c++0x or -std=gnu++0x [enabled by default]
bankNum.cpp:9:38: error: cannot convert â<brace-enclosed initializer list>â to âintâ in initialization
bankNum.cpp:30:3: error: expected â;â before âcoutâ
请看看http://stackoverflow.com/questions/7124899/initializer-list-for-dynamic-arrays –
不完整和错误,即使是最新的版本仍然有时会错过标准的一致性,当你试图推在C++上更难11新的语言功能...永远不要相信单个编译器的结果来说明代码是否正确形成。 – galop1n
@DieterLücking:够公平的;我很少直接使用'new',只用一个编译器检查语法。现在答案应该更加正确。 –