看c++ primer, 然后用c4droid做题目,发现个问
c4droid吧
全部回复
仅看楼主
level 5
zellwong 楼主
书上说在数组里可以用begin函数,使其返回指向数组首元素的指针,但是在已经include 了iterator及vector头文件后,编译器还是报错,说没找到begin函数,求解。谢谢各位。
2017年03月16日 01点03分 1
level 12
发源码
2017年03月16日 05点03分 2
level 5
zellwong 楼主
#include <iostream>
#include <vector>
#include <string>
#include <iterator>
using namespace std;
int main() {
int a = 5;
string b[a] = { "4", "5", "6", "2", "8" };
string *beg = begin(b);
string *last = end(b);
for (; beg != last; ++beg)
cout << *beg <<endl;
2017年03月17日 05点03分 3
level 12
#include <iostream>
//#include <vector>
#include <string>
//#include <iterator>
using namespace std;
int main()
{
const int a = 5; //要是常量
string b[a] = { "4","5","6","2","8" }; //最好用 vector<string>
auto beg = begin(b); //返回的是个迭代器, 不是 string*
auto last = end(b); //同上
for (; beg != last; ++beg)
cout << *beg << endl;
return 0;
}
2017年03月17日 06点03分 4
感谢,按你的做解决了
2017年03月18日 00点03分
1