#include <iostream>
#include <string>
#include <fstream>
using namespace std ;
string strWord(int index , string line)
{
int count = 0;
string word;
for (int i = 0 ; i < line.length(); i++)
{
if (line[i] == ' ')
{
if (line [i+1] != ' ')
{
count ++;
if ( count == index)
{
return word;
}
word ="";
}
}
else
{
word += line[i];
}
}
}
int main ()
{
ifstream inFile ;
inFile.open("new.txt");
string line , id;
cout <<"Enter id : ";
cin >>id;
while(!inFile.eof())
{
getline (inFile , line);
if (strWord (1, line) == id)
{
cout <<strWord (2 , line) <<endl;
break;
}
}
system("pause");
}
質問です:誰かが私はそれが何をしているかを取得しない私には、これを説明することができ、私はコンセプトを取得しますが、それぞれの行が何をやっている意味ですか?ファイルの行を取得し、行の2番目の単語を読み取るC++コード?
のコメントを望んでいました。この宿題ですか? – SingleNegationElimination
フォーマットを修正しました。 @ H4cKL0rD、それを4つのスペースをインデントすることでスタックオーバーフローに貼り付けるときにコードをフォーマットすることを忘れないでください。 –