c++ - How Do I use input to pass a string into a char array from a Text File -


hey know can use string read text file. need use char array. if using string this

while (!input.eof()){     input >> s; } 

i unsure how go if don't know length of string. know can use getline, i'll prefer use input.

i'm thinking maybe can use loop check until reaches "\0"?

anyway have feeling question has been asked before, if has can't find it. sorry if case.

you can consider istream::getline. note can use c++ string , must have length limit c string.

i think should avoid check eof directly in while condition. returns true reach end-of-file. if have multiple line, read it, calculate, consequence can unexpected when reach end-of-file right @ reading step. check of eof should placed right after reading stream example.

int main() {     ifstream input("filename.txt");     const int max = 10000;     char characters[max];     while (true) {         input.getline(characters, max - 1, '\n');         if (input.eof())             break;     } } 

Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -