c++ - unformatted input to a std::string instead of c-string from binary file -


OK, I have to work on this program using c-string. I am wondering if std: : Is it possible to read in the block underlined text in string? I chose the if & gt; & Gt; but it reads in line by line: I am breaking my code and trying to use std :: string beating my head against the wall, so I thought It was time to recruit experts.

I tried to fool it around:

  in.read Here there is a working program that gives you some content "a.txt" file is required. (Const_cast & lt; char * & gt; (memblock.c_str ()), read_size);  

But it was doing strange work. Send me the std :: cout & lt; & Lt; To print Memblock.c_str () , get it and do not clear the memblock.clear () string.

However, if you can think of a way to use STL, then I appreciate it.

Here my program is using c-strings

  // What this program does now: A new location byte byte by copy // it What the program is going to do: Get small blocks of a file and encrypt them # Include & lt; Fstream & gt; # Include & lt; Iostream & gt; #include & lt; String & gt; Int main (int argc, char * argv []) {int read_size = 16; Int infile_size; Std :: ifstream in; Std :: offream out; Four * memblock; Int complete = 0; Memblock = new four [read_size]; In.open ("a.txt", std :: ios :: | std :: ios :: binary | std :: ios :: ate); If (in.is_open ()) infile_size = in.tellg (); Out.open ("b.txt", std :: ios :: out | std :: ios :: trunc | std :: ios :: binary); In.seekg (0, std :: ios :: beg); // When opening the file (! In.eof ()) {complete = full + read_size; If (full> infile_size) {in.read (memblock, read_size); outside. Write (Mayblock, reading_size); } // end if else // last run {delete} [] memblock; Memblock = new four [infile_size% read_size]; In.read (memblock, infile_size% read_size + 1); Out.written (memblock, infile_size% read_size); } // end else} // end while} // main  

If you are looking at anything that will make this code better, please feel free to tell me.

Instead of using a std :: string , Std :: vector & lt; Consider using char & gt; ; The result of calling const_cast calls to you all the problems with std :: string :: c_str () . If you want to print the material, resize the vector size.

If you want to print the material, you can eliminate the content of the vector by pushing a null-terminator backwards:

  std :: vector & Lt; Char & gt; V; V.push_back ('\ 0'); Std :: cout & lt; & Lt; & Amp; V [0];  

Or you can convert it to std :: string :

  std :: vector < Char & gt; V; Std :: string s (v.begin (), v.end ());  

All of you believe that you have a block of text that you want to read from a binary file. If you are trying to print binary letters, this will not work, obviously this was not entirely clear to your question.


Comments