In the C++ programming language a vector is a form of dynamic line a class that includes a sequence of variables the precise figure of which can modify as required. Being up to work with text files in C++ is significant it lets your program to study configuration files and interpret scripts. A vector is a precise data structure for the purposes of copying a file for in-program utilize and can simply be done with only some lines of code.


Instruction:


Make a new ".cpp" file, whether that be by opening your text editor or beginning a new project in your compiler's development surroundings.


Import the essential libraries. The next list should cover all operations connected to file input, output and in-vector storage:

#include <algorithm>
#include <fstream>
#include <iterator>
#include <iostream>
#include <vector>

Paste this chunk of code into the ".cpp" file -- it should be located at the beginning of your source file.


Create the essential data containers in your main () function. You will require both an ifstream to pipe the file itself through and a vector for storage:

std::ifstream file("File.txt");
std::vector<char> input;

Replace "File.txt" with the name of the file you desire to copy into the vector containing the quotes around the name. All the next lines of code should be place successively in the main () function.


Stop the program from bouncing above whitespace characters by entering the following line of code:

file >> std::noskipws;


Copy the file into the vector:

std::copy(istream_iterator<char>(file), istream_iterator<char>(), std::back_inserter(input));


You can now do anything you similar to with the vector. To display the file onscreen:

std::copy(buffer.begin(), buffer.end(), ostream_iterator<char>(std::cout, ""));

Finish your main() function with the line:

return 0;

And a closing curly bracket. Amass the code and test-run it.