Visual Studio 没有 运行 我的代码,而其他 IDE 有
Visual Studio doesnt run my code while other IDE do
我正在为 Visual Studio 中的家庭作业编写代码,代码在我的第一个循环后立即停止,而其他 IDE 的 运行 则非常完美。
如果我替换cin>> str1 >> SizeDebt;仅用于 getline(cin,str1);它在 VS 中完美工作,因为 well.But 我不能这样做,因为我必须在由 space.
分隔的一行中输入向量和向量
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
unsigned int n,k,SizeDebt,i=0; // k can be ignored
string str1;
vector <string> Names;
vector <int> Debt;
do
{
cin >> n >> k;
} while (n<1 || k>1000000);
for ( ; i < n; i++)
{
cin >> str1 >> SizeDebt;
Names.push_back(str1);
Debt.push_back(SizeDebt);
}
cout << Names.size();
for ( i = 0; i < Names.size(); i++)
{
cout << Names[i] << endl;
}
cin.get();
}
你有没有使用调试器并一步一步地工作,然后它工作得很好吗?就我而言,这是由于程序的闪回让你产生代码在第一次循环后停止的错觉。
我建议您检查是否将子系统设置为 "console"(属性 -> 链接器 -> 系统 -> 子系统)?
然后在代码末尾添加如下语句
system("pause");
我正在为 Visual Studio 中的家庭作业编写代码,代码在我的第一个循环后立即停止,而其他 IDE 的 运行 则非常完美。
如果我替换cin>> str1 >> SizeDebt;仅用于 getline(cin,str1);它在 VS 中完美工作,因为 well.But 我不能这样做,因为我必须在由 space.
分隔的一行中输入向量和向量#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
unsigned int n,k,SizeDebt,i=0; // k can be ignored
string str1;
vector <string> Names;
vector <int> Debt;
do
{
cin >> n >> k;
} while (n<1 || k>1000000);
for ( ; i < n; i++)
{
cin >> str1 >> SizeDebt;
Names.push_back(str1);
Debt.push_back(SizeDebt);
}
cout << Names.size();
for ( i = 0; i < Names.size(); i++)
{
cout << Names[i] << endl;
}
cin.get();
}
你有没有使用调试器并一步一步地工作,然后它工作得很好吗?就我而言,这是由于程序的闪回让你产生代码在第一次循环后停止的错觉。
我建议您检查是否将子系统设置为 "console"(属性 -> 链接器 -> 系统 -> 子系统)?
然后在代码末尾添加如下语句
system("pause");