나는 다음과 같은 C++ 코드를 한 : 문제왜 istringstream에서 데이터를 읽는 중 오류가 발생합니까?
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <iomanip>
#include <cstring>
using namespace std;
int main() {
istringstream inSS;
string title;
string col1;
string col2;
string val;
int numCommas;
vector<string> stringData();
vector<int> intData();
cout << "Enter a title for the data:" << endl;
getline(cin, title);
cout << "You entered: " << title << endl << endl;
cout << "Enter the column 1 header:" << endl;
getline(cin, col1);
cout << "You entered: " << col1 << endl << endl;
cout << "Enter the column 2 header:" << endl;
getline(cin, col2);
cout << "You entered: " << col2 << endl << endl;
while (1) {
cout << "Enter a data point (-1 to stop input):" << endl;
getline(cin, val);
if(strcmp(val.c_str(), "-1") == 0) {
break;
}
inSS >> stringData >> intData;
cout << "Data string: " << stringData << endl;
cout << "Data integer: " << intData << endl;
}
return 0;
}
오류 :
main.cpp: In function 'int main()': main.cpp:46:9: error: no match for 'operator>>' (operand types are 'std::istringstream {aka std::cxx11::basic_istringstream<char>}' and 'std::vector<std::cxx11::basic_string<char> >()')
inSS >> stringData >> intData;
~~~^~~~~~~~~~~
이 오류가 무엇을 의미합니까? 어떻게 수정해야합니까?
'stringData'는 벡터이고, 벡터는'>>'에 오버로드를 제공하지 않습니다. 'inSS >> stringData >> intData;'무엇을 기대합니까? – Carcigenicate
상당히 간단합니다. 그것은 당신이 사용하고있는'operator >> 연산자가없는'basic_istringstream' (즉,'inSS')과'vector' (즉'stringData'와'intData')를 사용하고 있다는 것을 말하고 있습니다 inSS >> stringData >> intData;'). –
그렇다면 어떻게 사용자 입력을 벡터에 저장합니까? 이 할당을 위해 우리는 istringstream과 벡터를 사용하기로되어 있습니다. – Chase