아래는 실패한 시도이며 터미널은 'lengthCapture'로 0을 읽습니다. 나는 기쁨없이 대답을 검색해 보았다.
내 텍스트 파일의 제목은 'Boogiedy.txt'이고 'Boogiedy, Boogiedy, Boooooo'로 표시됩니다.
터미널은 다음과 같습니다.
Boogiedy, Boogiedy, Boooooo
27
0
내 코드 :
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
string boogiedy;
int lengthCapture = boogiedy.length();
ifstream inputFile ("boogiedy.txt");
if(inputFile.is_open())
{
while (getline(inputFile,boogiedy))
{
cout <<boogiedy<< '\n';
cout <<boogiedy.length() << endl;
}
}
else
cout << "file is not open" << '\n';
inputFile.close();
cout << lengthCapture << endl;
}
문자열의 크기를 얻을 때 변수는 여전히 비어 있습니다.
이 시도:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
string boogiedy;
int lengthCapture = 0;
ifstream inputFile ("boogiedy.txt");
if(inputFile.is_open())
{
while (getline(inputFile,boogiedy))
{
cout <<boogiedy<< '\n';
cout <<boogiedy.length() << endl;
lengthCapture += boogiedy.length();
}
}
else
cout << "file is not open" << '\n';
inputFile.close();
cout << lengthCapture << endl;
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다