Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <vector>
- using namespace std;
- int main(){
- cout << "Name of file: ";
- string fileName;
- cin >> fileName;
- ofstream myFile(fileName);
- if(myFile.is_open()){
- vector<string> userData;
- cout << "Enter how many words you'd like to write to file: ";
- int wordCount;
- cin >> wordCount;
- for(int i = 0; i < wordCount; i++){
- cout << "Enter word " << i + 1 << ": ";
- string uInput;
- cin >> uInput;
- userData.push_back(uInput);
- userData.push_back(" ");
- }
- for(unsigned int i = 0; i < userData.size(); i++){
- cout << "Data: '" << userData[i] << "' written successfully" << endl;
- myFile << userData[i];
- }
- myFile.close();
- }else{
- cerr << "File could not open!" << endl;
- }
- system("pause");
- return 0;
- }
Add Comment
Please, Sign In to add comment