나는 단어 목록을 작성했는지 코드를 작성하고 있습니다. 여기에는 '단어'와 '설명'이 포함됩니다. 단어와 설명에는 고유 한 벡터가 있습니다. 나는지도를 사용해서도 똑같이 노력하고있다.C++ Wordlist; 벡터 /지도에서 전체 설명 찾기
단어를 조회하려고 할 때까지 프로그램이 잘 진행 중입니다. 프로그램은 설명에서 마지막 단어 만 가져옵니다. 단일 벡터에 대해 전체 문장을 만드는 방법이 있습니까?
이것은 설명을 적어 두는 코드입니다. 전체 프로그램 코드는 정말 오랫동안 난 단지 중요한 물건을 말할 것이다, 그래서입니다 :
cout<< "Describe your word:"; //Describtion by using vectors
cin>> desc; //Here you enter the decribtion
getline(cin, desc); //So you can have "space" and write a whole sentence.
d.push_back(desc); //Place the describe at the back of the list so it is at the same index as the matching word
을 그리고이 단어와 describtion 표시하도록되어 코드입니다 :
cout<< "Enter a word to lookup:";
cin>> word;
if (find(o.begin(), o.end(), word) !=o.end()) //Lookup if word excist in vector
{
int pos = find(o.begin(), o.end(), word) - o.begin(); //Searches which index the word is in the vector
cout<< "Describtion for " << word << " is " << d[pos] << endl; //d[pos] takes the description vector that is in the same index as the word vector
}
else
cout<< "Word not found! Try something else." << endl; //If word not found
것은 그것은 단지 걸릴 것이다 그 말의 마지막 단어. 지도를 사용하여 동일한 문제가 발생했습니다.
cout<< "Enter a word to lookup:";
cin>> word;
if (L.find(word) != L.end()) //Lookup if the key excist
{
cout<< "Describtion for " << word << " is " << L[word] << endl; //Tells what the description is for the word if it excist
}
else
cout<< "Word not found! Try something else." << endl; //Tells you this if key is not found
그렇다면 특정 단어에 대해 전체 설명을 인쇄하려면 어떻게해야합니까?
편집 : 나는
그래서, 무슨 일이다 (I 2보다 더 많은 단어하지 충분히 바보) 누락 년대 describtion에서 첫 번째 단어입니다 것으로 나타났습니다? 출력물의 설명 부분에 프리스트 단어를 어떻게 얻을 수 있습니까?
모두 테스트 한 설명에 두 단어가 있습니까? – molbdnilo
그래, 지적 해 주셔서 고마워, 첫 단어 만 건너 뛰고있는 것처럼 보입니다. – Supermixerman
독서 코드의 모든 줄 사이에'cout << desc << endl;'을 추가하십시오. – molbdnilo