标题:这个为什么会报错?(关于vector的问题)
取消只看楼主
a74692074
Rank: 1
等 级:等待验证会员
帖 子:7
专家分:0
注 册:2018-7-19
结帖率:100%
已结贴  问题点数:20 回复次数:5 
这个为什么会报错?(关于vector的问题)
#include <iostream>
#include <vector>
#include <array>
using namespace std;

int main()
{
    double a1[4] = {1.2, 2.4, 3.6, 4.8};
    vector<double> a2(4);
    a2[0] = 1.0/3.0;
    a2[1] = 1.0/1.5;
    a2[2] = 1.0/7.0;
    a2[3] = 1.0/9.0;
    array<double, 4> a3 = {3.14, 2.72, 1.62, 1.41};
    array<double, 4> a4;
    a4 = a3;
    cout << "a1[2]:" << a1[2] << " at " << &a1[2] << endl;
    cout << "a2[2]:" << a2[2] << " at " << &a2[2] << endl;
    cout << "a3[2]:" << a3[2] << " at " << &a3[3] << endl;
    cout << "a4[2]:" << a4[2] << " at " << &a4[4] << endl;
    a1[-2] = 20.2;
    cout << "a1[-2]: " << a1[-2] << " at " << &a1[-2] << endl;
    cout << "a3[2]:" << a3[2] << " at " << &a3[2] << endl;
    cout << "a4[2]:" << a4[2] << " at " << &a4[2] << endl;
    return 0;
}
搜索更多相关主题的帖子: vector include array double cout 
2018-07-19 16:14
a74692074
Rank: 1
等 级:等待验证会员
帖 子:7
专家分:0
注 册:2018-7-19
得分:0 
有没有大神能帮帮忙??!
2018-07-19 16:15
a74692074
Rank: 1
等 级:等待验证会员
帖 子:7
专家分:0
注 册:2018-7-19
得分:0 
回复 3楼 mj0011
编译器还是报错
2018-07-19 16:21
a74692074
Rank: 1
等 级:等待验证会员
帖 子:7
专家分:0
注 册:2018-7-19
得分:0 
回复 5楼 mj0011
#include <iostream>
#include <vector>
#include <array>
using namespace std;

int main()
{
    double a1[4] = {1.2, 2.4, 3.6, 4.8};
    vector<double> array(4);
    a2[0] = 1.0/3.0;
    a2[1] = 1.0/1.5;
    a2[2] = 1.0/7.0;
    a2[3] = 1.0/9.0;
    array<double, 4> a3 = {3.14, 2.72, 1.62, 1.41};
    a4 = a3;
    cout << "a1[2]:" << a1[2] << " at " << &a1[2] << endl;
    cout << "a2[2]:" << a2[2] << " at " << &a2[2] << endl;
    cout << "a3[2]:" << a3[2] << " at " << &a3[3] << endl;
    cout << "a4[2]:" << a4[2] << " at " << &a4[4] << endl;
    a1[-2] = 20.2;
    cout << "a1[-2]: " << a1[-2] << " at " << &a1[-2] << endl;
    cout << "a3[2]:" << a3[2] << " at " << &a3[2] << endl;
    cout << "a4[2]:" << a4[2] << " at " << &a4[2] << endl;
    return 0;
}
2018-07-19 16:25
a74692074
Rank: 1
等 级:等待验证会员
帖 子:7
专家分:0
注 册:2018-7-19
得分:0 
回复 7楼 mj0011
没听懂你可以帮我修改一下吗?谢谢好人!
2018-07-19 16:30
a74692074
Rank: 1
等 级:等待验证会员
帖 子:7
专家分:0
注 册:2018-7-19
得分:0 
回复 10楼 mj0011
我已经知道了,是语法有错误,谢谢啦
2018-07-20 09:32



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-488695-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.267254 second(s), 9 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved