【发布时间】:2014-10-27 21:12:20
【问题描述】:
所以,我使用的是 dev-C++。编译器工作正常,一个简单的 hello world 程序与大约十几个其他简单程序一起工作。这是我正在为课堂做的事情的进行中的工作。
对我来说,它可以编译,但它永远不会运行。它出什么问题了?
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
using namespace std;
void getNames(vector<string> &vectorName, int &last, string temp);
int main() {
vector<string> names;
string tmp;
int last = 0;
getNames(names, last, tmp);
for(int j = 0; j < last; j++) {
cout << names.at(j) << endl;
}
system("PAUSE");
return EXIT_SUCCESS;
}
void getNames(vector<string> vectorName, int &last, string temp) {
while (true) {
cout << "Enter a name (quit to stop): ";
cin >> temp;
if (temp == "quit") break;
vectorName.push_back(temp);
last = vectorName.size();
}
}
【问题讨论】:
-
定义“从不运行”。如果手动运行呢?你看到任何错误吗?如果有,它们是什么?
-
我看到的第一件事是
getNames定义的参数与您声明的参数不同(缺少&) -
在您的
main函数中的getNames上放置一个断点,看看它是否到达那里。如果是,请按 F10 直到它停止工作,并让我们知道它在哪里停止工作
标签: c++