c++ - Reading from an input file -


#include <iostream> #include <fstream> using namespace std;  int main(int argc, char *argv[]) {     int size = 0;     int highnum = 0;     int m;     string fname;      cout << "supply name of input file use." << endl;     cin >> fname;      ifstream input;     input.open(fname.c_str());     input >> size;     int numbers[size];      (int n = 0; n < size; n++)         input >> numbers[n];      (m = 0 ; m < size ; m++)     {         if (numbers[m] > highnum)             highnum = numbers[m];     }     int j;     int k;     bool values[] = {false, false, false, false, false, false};      (j = highnum; j > 0 ; j--)     {         (k = size - 1 ; k >= 0 ; k--)         {             if (j <= numbers[k])                 values[k] = true;         }          if (values[0])             cout << "| xxx";         else             cout << "|    ";         if (values[1])             cout << "   +++";         else             cout << "      ";         if (values[2])             cout << "   ***";         else             cout << "      ";         if (values[3])             cout << "   ---";         else             cout << "      ";         if (values[4])             cout << "   +++";         else             cout << "      ";         if (values[5])             cout << "   +++" << endl;         else             cout << "      " << endl;      }      return 0; } 

i trying write code print bar chart reading integers separate text file. posted complete code, know bottom half works if input numbers. wondering problem given there data file in same directory. when run program , enter name of data file created test it, program runs, no graph produced.

your program works me. suppose input file isn't present in current working directory of process. suggest add check see if input valid after call open.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -