CSV 파일의 데이터를 저장하고 핵심어를 검색하는 프로그램을 만들려고합니다. 나는이 코드를 가지고 있고, 표시 오류가없는,하지만 늘를 요청하는 프로그램의 과거를 실행 '단어를 입력 :'(? 여러 단어를) 정확한 문자열을 포함하는 std::cin
을 얻기 위해C++ CSV 파일에서 단어 검색
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <sstream>
using namespace std;
int main(){
vector<string> student(860);
vector<string> question(860);
vector<string> answer(860);
int count = 0;
string word;
ifstream file("data2.csv");
if (!file.is_open())
cerr << "File not found" << endl;
while (file.good()){
for (int i = 0; i < 860; i++){
getline(file, student[i], ',');
getline(file, question[i], ',');
getline(file, answer[i], ',');
}
}
cout << "Enter word: ";
cin >> word;
for (int j = 0; j < 860; j++){
if (answer[j].find(word) != std::string::npos){
cout << student[j] << question[j] << answer[j] << endl;
count++;
}
}
cout << count;
return 0;
}
@JakeFreeman 그것은 무한 루프가 아니며 그는'Enter Word'를 실행한다고 !! 내 대답을 아래에서 읽으십시오 – organicoman
@organicoman 좋아, 내가 문장을 잘못 읽었습니다 –