File operations Flashcards
What is the library we want to use?
include
How do we make a stream? What is a stream?
std::ofstream output;
> This is used to declare a connection (object) to a file
How do you open a file to write to?
output.open(“output.txt”);
How do you check to see if the file opened?
output.is_open()
How do you stop writing to a file?
output.close();
How do you add to a file without overwriting data?
using ‘std::fstream::app output;’
how do you write to a file?
output «_space;“string” «_space;std::endl
How do you make a stream to read a file?
std::ifstream input;
How do you check a stream to read a file has opened?
input.is_open();
How do you read from a file?
std::string input_string;
input»_space; input_string;
How do you read until a character?
getline(input, input_string, ‘,’);
How do you read until the end of a line?
getline(input, input_string);