【发布时间】:2014-02-11 18:17:10
【问题描述】:
我有这个初步代码:
#include "std_lib_facilities_4.h"
void numbers()
{
vector<int> first(9);
for (int i = 0; i <= 9; ++i)
{
cout << i << endl;
first.push_back(i);
}
for (int j = 0; j <= 9; ++j)
cout << first[j];
}
int main()
{
numbers();
}
我希望在打印每个元素时都能打印出数字 1、2、3、4、5、6、7、8 和 9。相反,我得到了这个:
0
1
2
3
4
5
6
7
8
9
0000000000
我做错了什么?
【问题讨论】:
-
什么是 std_lib_facilities_4.h?
-
哦,对不起,我应该提到这一点。 std_lib_facilites_4.h 是我的教授专门为我的 C++ 课程制作的普通 std_lib_facilites.h 的编辑版本。据我所知,基本相同,只是做了一些改动。
-
什么是普通的
std_lib_facilites.h? -
@Nabla:可能是 Bjarne Stroustrup 书中的那个:stroustrup.com/Programming/std_lib_facilities.h