다음 코드를 사용하여 파일에서 데이터 쌍을 읽으려고합니다. 컴파일 할 때파일에서 데이터 쌍을 읽는 중
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
int main()
{
//**** Opening data file ****
ifstream infile;
infile.open("reg_data_log.inp");
if (infile.is_open())
{
cout << "File successfully open" << endl;
}
else
{
cout << "Error opening file";
}
//**** Reading data ***
vector<pair<double, double> > proteins;
pair<double, double> input;
while (infile >> input.first >> input.second)
{
proteins.push_back(input);
}
//**** Show data in screen ****
cout << "Proteins analized: " << proteins.size() << endl;
for(unsigned int i=0; i<proteins.size(); i++)
{
cout << i.first << ", " << i.second << endl;
}
}
나는 다음과 같은 메시지를 내가이 문제를 해결 내 머리를 얻을 수
"65:13: error: request for member ‘first’ in ‘i’, which is of non-class type ‘unsigned int’"
"65:13: error: request for member ‘first’ in ‘i’, which is of non-class type ‘unsigned int’"
있습니다. 아무도 도와 줄 수 있니?
감사
오류가 명확합니다. 마지막 루프에서'i'를 사용합니다. 그것은'int'입니다. 그러나 당신은'i.first'에 접근하려고합니다. –
이터레이터를 사용해야합니다. 예 :'for (auto i : proteins) {cout << i.first << ","<< i.second << endl;}' –
iterator는 컴파일러 오류 63 : 7을줍니다 : 경고 : 'auto' C++ 11에서 의미를 변경합니다. 그것을 제거하십시오 [-WC++ 0x-compat] – berkboy