これが私が書いたコードです。ご覧のとおり、単純なテンプレートの PRINT 関数があります。実際には INT 型のベクトルでは機能しますが、DOUBLE では機能しません。何が問題なのですか?
#include <iostream>
#include <vector>
using namespace std;
template <typename T>
void print (vector<T> &v) {
for (int i=0; i<v.size(); i++)
cout<<v[i]<<'\t';
}
int main() {
vector<int> vec;
int a;
while (cin>>a)
vec.push_back(a);
print(vec);
vector<double> vec1;
double b;
while (cin>>b)
vec1.push_back(b);
print(vec1);
return 0;
system("pause");
}
while (some_integer<10) のように、定義された while サイクルでテストしましたが、動作しますが、実行する回数の値が定義されていないと動作しません。それを理解できませんでした