Problem Input/Output with files

Hello guys i have a little problem, i want to make a simple Input/Output program that will print my writed line i have readed this: (http://www.cplusplus.com/doc/tutorial/files/) But i dont get it much so i make this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <cstdlib>
#include <iostream>
#include <fstream>

using namespace std;

int memoria()
{
    string odgovor;
    ifstream potcetnikFile ("potcetnik.txt");
    if (potcetnikFile.is_open())
    {
       while ( potcetnikFile.good() )
    {
       getline (potcetnikFile,odgovor);
       cout << odgovor << endl;
    }
    potcetnikFile.close();
  }

  else cout << "Unable to open file" << endl;
  system("pause");

  return 0;
}

int main(int argc, char *argv[])
{
    int odgovor, i;
    cout <<"Sto planirash da pravis denes ?" << endl;
    cin >> odgovor;
    ofstream potcetnikFile;
    potcetnikFile.open("potsetnik.txt");  // Open a text file.
    potcetnikFile << odgovor;  // Output contents of var1 to data.txt.
    potcetnikFile.close();
    memoria();
    return 0;
}

I dont get what i want, tells me " Unable to open file "
Thanks. :)
Last edited on
In main: "potsetnik.txt"
In memoria: "potcetnik.txt"

potsetnik.txt is not potcetnik.txt
i changed but gives me now some numebrs "112" all time...
Topic archived. No new replies allowed.