firstFileStream[50]
이라는 문자 배열이 있는데, 이는 fstream을 사용하여 infile에서 기록됩니다.어떻게 char 배열을 C++의 문자열로 변환 할 수 있습니까?
이 문자 배열을 firstFileAsString
이라는 문자열로 변환하고 싶습니다. string firstFileAsString = firstFileStream;
을 쓰면 배열 내의 첫 번째 단어 만 쓰고 첫 번째 공백이나 빈 문자에서 멈 춥니 다. 내가 firstFileAsString(firstFileStream)
이라고 쓰면 나는 같은 출력을 얻는다.
어떻게 전체 문자 배열을 그 안에있는 모든 단어를 문자열로 쓰나요? zdan가 지적했듯이, 난 단지 파일의 첫 번째 단어를 읽고 있었다, 그래서 대신 내가 지정하는 istreambuf_iterator<char>
을 사용했습니다,
string firstInputFile = "inputText1.txt";
char firstFileStream[50];
ifstream openFileStream;
openFileStream.open(firstInputFile);
if (strlen(firstFileStream) == 0) { // If the array is empty
cout << "First File Stream: " << endl;
while (openFileStream.good()) { // While we haven't reached the end of the file
openFileStream >> firstFileStream;
}
string firstFileAsString = firstFileStream;
}
어떻게 당신은 얼마나 많은 문자를 복사하는 지 알고 있나요? – juanchopanza
입력 파일의 길이가 공백을 포함하여 해당 문자 수를 포함합니다. – fauliath
@ Magis 50자를 복사해야하는지 또는 일부 비밀 번호입니까? – juanchopanza