Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Read data from file into arrays in c++ 2011
#1
Read data from file into arrays in c++ 2011

Code:
#include <iostream> #include <fstream> #include <string> #include <iomanip> #include <cmath> #include <ctime> using namespace std; const string AUTHOR = "Rf"; const string ROLE = ", (s)\n"; const string SOLTXT = "\nSolution by "; const string INFILE_ERR_MSG = "File does not exist or it is empty!\n"; const int EXIT_ERR_INFILE = -1; // Error with input file const int MAX_INT = 500; bool openFileForInput(ifstream&); int main() { ofstream outData("INTEGERS.TXT"); time_t t; time(&t); srand (t); int base = -250; int num; for (int i = 0; i < MAX_INT; i++) { outData << (num = base + rand()%500) << endl; } outData.close(); ifstream inData; // Open a file for input // Check for existence of file in current directory // If file exists, is there any data in the file if (!openFileForInput(inData)) { cout << INFILE_ERR_MSG; system("PAUSE"); return EXIT_ERR_INFILE; } cout << endl << endl; system ("PAUSE"); return 0; } bool openFileForInput(ifstream& inp) { char check; inp.open("INTEGERS.TXT"); // See if we can open check = inp.peek(); // Determine whether file is not empty if (inp && !inp.eof() ) // checks if the file exists and not empty return true; return false; } /* End of openFileForInput() */ bool getNum(ifstream& inp, ofstream& otp)// this is where I'm stuck { int num; unsigned int neg[]; int posEven[]; int posOdd[] inp >> num; if (inp && !inp.eof()) { cin >> inp >> int posEven[num] return true; } return false; }

0300-9520262
Get solution in 24 hour
|cpmputer & internetConfusedmileys81:[SIZE="4"][SIZE="3"]....[/SIZE][/SIZE]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Abstract data type (ADT) in C++ 2012 Vuhelper 0 7,104 01-04-2012, 10:34 PM
Last Post: Vuhelper
  call by value, call by reference,call by pointer in data structure 2012 Vuhelper 0 4,332 01-04-2012, 10:28 PM
Last Post: Vuhelper
  Balance of the AVL tree im Data structure 2012 Vuhelper 0 1,901 01-04-2012, 10:27 PM
Last Post: Vuhelper
  array project code c++ 2011 Vuhelper 0 1,272 12-10-2011, 06:32 PM
Last Post: Vuhelper
  factorial in C++ code 2011 Vuhelper 0 943 12-10-2011, 06:31 PM
Last Post: Vuhelper
  why we use queues data structure for level order traverse? Vuhelper 0 2,465 11-05-2011, 05:26 PM
Last Post: Vuhelper
  how to make .h file in c++ Vuhelper 0 3,620 11-05-2011, 05:20 PM
Last Post: Vuhelper
  Linklist Data Structure Vuhelper 0 1,894 11-05-2011, 05:11 PM
Last Post: Vuhelper
  Linked list using arrays? Vuhelper 0 2,372 11-05-2011, 05:07 PM
Last Post: Vuhelper
  stack during function call in C++ 2011 Vuhelper 0 2,025 11-05-2011, 05:05 PM
Last Post: Vuhelper

Forum Jump:


Users browsing this thread: 1 Guest(s)