c++ - How to write from array to outputfile? -
i have vector vec (256, 0) use record type of characters , frequency input file. given 3 a's vec[65] hold value of 3. trying write output file count non-empty chars in total followed ascii character , frequency of occurrence.
int count = 0; (int = 0; < 256; i++) if (vec[i] != 0) // if not 0 count count++; // print count first char in output file outfile << count; (int = 0; < 256; i++) if (vec[i] != 0) outfile << (char) << vec[i];
given input "a bb c" want is:
4a1b2c1
but is:
5
1 2a1b2c1
what can fix this?
your input file looks this: "a bb c\r\n" instead of "a bb c". means have 5 character types: 1 '\n' (ascii code: 10), 1 '\r' (ascii code: 13), 2 spaces (ascii code: 32), 1 'a', 2 'b' characters, , 1 'c'. code works correctly! problem is, when print '\r', '\n' , ' ' output file, show whitespaces.
if remove newline input file, "a bb c" input, output this: "4 1a1b2c1", because ascii code of space less ascii code of 'a'.
Comments
Post a Comment