I made some test file for an assignment that I'm doing, but I am not sure why vim is giving me extra characters at the end of file.
So I made an "ABC" file that contains A, B, and C with no new line at the end. So something like
vim ABC
AAAABBBCC
I outputted a portion of my read code
46 while(1) {
47 ch = infile.get();
48 if(infile.eof()) {
49 break;
50 }
51 cout << '~' << ch << '~' << (int)ch << '~' << endl;
52 v[(int)ch]++;
53 }
and I got
~A~65~
~A~65~
~A~65~
~A~65~
~A~65~
~B~66~
~B~66~
~B~66~
~C~67~
~C~67~
~
~10~
I am not sure why I am getting a newline character in my input file
with no new line at the end
No, you do have a newline character at the end. The newline functions as a line terminator , not a line separator , which is why even the last line is followed by '\\n'.
You can get vim to write an unterminated line with :set binary noeol
, if you really need to, but it is then no longer what both vim and C++ consider a text file.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.