[英]C++ - Gettings size from vector in FOR loop
I have a loop that asks for user input, and adds it too a vector, then when if they type "EXIT" it will stop and display the list. 我有一个循环,询问用户输入,并添加它也是一个向量,然后如果他们键入“退出”它将停止并显示列表。 What I am trying to do now is determine the number of elements with
size()
我现在要做的是确定
size()
的元素数量
This is what I have: 这就是我所拥有的:
#include <iostream>
#include <string>
#include <unistd.h>
#include <iterator>
#include <vector>
using namespace std;
int main()
{
write(1,"\E[H\E[2J",7);
vector<string> list;
cout << "Enter UIDs: \n\n";
for(string uid ; cin >> uid && uid != "EXIT"; list.push_back(uid))
cout << " \n";
copy(list.begin(), list.end(), ostream_iterator<string>(cout, "\n\n"));
cout << "Vector size: " << uid.size() << endl;
return 0;
}
When attempting to compile that I get the error: 在尝试编译时,我收到错误:
g++ sof.cpp -o sof g ++ sof.cpp -o sof
sof.cpp: In function 'int main()':
sof.cpp:在函数'int main()'中:
sof.cpp:16:32: error: name lookup of 'uid' changed for ISO 'for' scopingsof.cpp:16:32:错误:'uid'的名称查找已更改为ISO'for'scoping
sof.cpp:13:16: error: cannot use obsolete binding at 'uid' because it has a destructorsof.cpp:13:16:错误:不能在'uid'使用过时的绑定,因为它有一个析构函数
你在查询uid.size()
而不是list.size()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.