Need help with input/output

+1 Artur Yasinskiy · November 3, 2015
Here is the code:

std::string textf;
        system("cls");
        cout << "--Enter Your Text--" << endl;
        ofstream file_;
        file_.open("Text.txt");
        getline(std::cin, textf);
        file_ << textf << endl;

This part of the program is supposed to gather your input using strings and making a text file, but when I compile and run, It just exits out of the program.

Post a Reply

Replies

Oldest  Newest  Rating
0 Howard Sloat · November 14, 2015
Try placing a std::cin.ignore(); . 'cin' has a reputation for leaving a CR in the keyboard input buffer, so
your getline() reads it and thinks it's done, cin.ignore() can remove one or more remaining characters.
Good luck!
  • 1

C++

107,068 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator