I'm experimenting with writing to and reading from .txt files in C++. I can make a program that writes to a .txt file successfully, but whenever I try to make it read from that text file, it only shows the first word. Here's the code.
#include <iostream> #include <fstream>
using namespace std;
int main() { char txt[100]; ofstream a_file ( "hat.txt" ); a_file<<"I AM the Warhat."; a_file.close(); ifstream b_file ( "hat.txt" ); b_file>> txt; cout<< txt <<"\n"; cin.get(); }
|