0
단일 txt 파일을 읽는 것으로 여러 개의 이진 트리를 만들려고합니다. 이렇게하려면 줄의 각 문자를 읽고 트리를 만든 다음 다른 트리를 만들기 위해 다음 줄로 이동해야합니다. 현재 코드가 입력 줄을 한 줄씩 잡아 내고 있으며이를 변경하는 방법을 모르겠습니다. , std::noskipws
초기 공백 문자를 추출 할 수있는 유효한 내용을 의미문자와 문자를 한 줄씩 문자별로 txt 파일을 읽는 방법 C++
int main()
{
vector <BinaryTree <string> > BT;
int iteration = 0;
string line;
ifstream myfile("input.txt");
if (myfile.is_open())
{
while(getline (myfile, line))
{
BinaryTree <string> temptree;
BT.push_back(temptree);
BT[iteration].InsertData(line);
cout << "Preorder: ";
BT[iteration].PrintPreorder();
cout << endl;
cout << "Inorder: ";
BT[iteration].PrintInorder();
cout << endl;
cout << "Postorder: ";
BT[iteration].PrintPostorder();
cout << endl;
cout << "Reverse Inorder: ";
BT[iteration].PrintReverseInorder();
cout << endl;
BT[iteration].PrintPrintTree();
cout << endl;
iteration++;
myfile.close();
}
return 0;
}
또한'char c = ifs.get()'을 사용할 수도 있습니다. –