I am trying to make a program that takes input from a .txt document and copies it to another .txt document. I understand that the >> operator of ifstream stops at each whitespace. Is there any way to set it so that it reads through the whitespace? For example, if I wanted to copy this sentence...
"This is a sentence I would like to copy."
from one .txt to another .txt, using >> would only copy the "This" string. Is there a way to make it read through the whitespace so it copies the entire sentence? Or do I have to tokenize the sentence in a loop using " " as my delimiter? Here is a watered down version of my code. Thanks.
Code:#include <fstream> #include <iostream> #include <cstring> using namespace std; int main(){ string str; ifstream inputFile ( "input.txt" ); //input.txt contains sentence I want to copy inputFile >> str; inputFile.close(); ofstream outputFile ( "output.txt" ); outputFile << str; outputFile.close(); return 0; }