Let's suppose I want to append 5 numbers in a file called numbers.txt
It's running the program; however, it never creates the file numbers.txt; therefore it always displays "file could not be created". Am i missing something?
Code:// ch 9.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <iostream> #include <string> #include <fstream> using namespace std; int main() { int numbers[5] = {0}; ofstream numberSequence; for (int x = 0; x < 5; x++) { cout << "enter digit " << endl; cin >> numbers[x]; } cout << endl << "These number will be stores in a file:" <<endl; numberSequence.open("numbers", ios ::app); if (!numberSequence.is_open()) { for (int p = 0; p < 5; p ++) { cout << endl << numbers[p] << endl; numberSequence << numbers[p] << '#' << endl; } } else cout << "file could not be created" << endl; system("pause"); return 0; }




Reply With Quote