---------------------------------------

closed account (STR9GNh0)
will figure out by myself instead. thanks
Last edited on
1st your English is bad.
2nd do you know what ifstream does ? As i cant see where you add the OFSTREAM !!
3rd cout ? are you serious ? man you have to choose between the <fstream> and <iostream>
4th *heap, is a pointer. do you know what tht is ?

PS: go check the cplusplus tutorial and rewrite your code.
closed account (STR9GNh0)
ok... means what ? all i want is to read the numbers from a file (i don't quite understand why do i need a ofstream for?)... and cout into the compiler and view the results, it doesn't work in this way?
Last edited on
nope !
if you want read from file than you must Print the result TO FILE too.
tht is done by

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <fstream>
using namespace std;
int main()
{
   int a,b,c;                                          // variables
   ifstream in("yourfile.in");                 // here you declare the file from where the variables will be read
   ofstream out("yourfile.out");          // here you declare the file in which you print the result
   in >> a;                                          // this is the "cin" in the <fstream>
   in >> b;                                          // this is the "cin" in the <fstream>
   c = a+b;
   out << c;                                        // this is the "cout" int the <fstream>
   in.close();                                       // you close the reading file
   out.close();                                    // you close the printing file
   return 0;
}

closed account (STR9GNh0)
--------------------------------
Last edited on
well, im not so sure about that, wait 1 moment ill try to do a simple program.
USE THIS CODE ! IT WORKS !

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>                                // for cout
#include <fstream>                                 // to be able to read from file
using namespace std;
int main()
{
   int a,b,c;                                      // variables
   ifstream in("yourfile.in");                     // here you declare the file from where the variables will be read
   in >> a;                                        // this is the "cin" in the <fstream>
   in >> b;                                        // this is the "cin" in the <fstream>
   c = a+b;
   cout << c;
   in.close();                                     // you close the reading file
   return 0;
}
closed account (STR9GNh0)
----------------------------------------
Last edited on
1
2
3
4
5
6
// dont forget to type:
ifstream in("GiveAnameToTheFile.in");
//THE .in !! and NOT .txt !!!
// and also dont forget to do:
in.close();
// at the end of file ! 
closed account (STR9GNh0)
----------------------------------------
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include <fstream>

using namespace std;

void inOrder(int[], int, int);
void makeHeap(int[], int, int);
void swapNode(int [], int, int);
void siftDown(int[], int, int);
void heapSort(int[], int);

int main()
{
    fstream infile("input.txt");


This is completly WRONG !

instead of the fstream infile("input.txt"); you should have written ifstream infile("input.in");

and at end you should add in.close();
Last edited on
sorry i didnt see your message ... ill try to help
1
2
3
4
5
6
7
8
void heapSort(int arraylist[], int size)
{
    for (int i = size; i>1; i--)
    {
        swapNode(arraylist, 1, i); // swap first and last node
        siftDown(arraylist, 1, i-1); // siftdown tree
    }
}


seems to be ok, just try what i said. 1st change the input.txt into input.in and add infile.close() at end;
closed account (STR9GNh0)
----------------------------------------
Last edited on
@nanochan1: could you give us another chance? (common, it was just 1 hour).
I hope you can fix it, good luck.
Topic archived. No new replies allowed.