it will not open text file help

a
Last edited on
i'm wanting to display the information of the program onto a text file. can someone help please

Wait a minute: what is your exact problem? If you just do

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <fstream>

using namespace std;

int main()

{
     ofstream fout;
     fout.open("big.txt");
     fout << "biggfgfdgdfgfdgdfgdf" << endl;
     fout.close();

     return 0;
}


then everything is ok and that string is written correctly to the file. Then what do you want to do? Print the result of that calculation on the file too? Well... the code is exactly the same. The only thing that changes is what you want to print.
Last edited on
that's the bit i'm not understanding. i can't make it print

i can make the txt file open but i can't print the results

how would i do this?
i need the results from the program to print in the text file
Probably this solves your problem:

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
#include <iostream>
#include <fstream>
#include <cmath>

using namespace std;

int main()

{
     ofstream fout;
     fout.open("big.txt");
     fout << "biggfgfdgdfgfdgdfgdf" << endl;

     float a, c, d;
     c = 0;
     while (c < 101) {
          d = (5 * ((c * 1.8) + 32) + 2297) / 2457;
          a = 325.8 * sqrt(d);
          // print on the screen (console)
          cout << c << endl << a << endl;

          // print on the file
          fout << c << endl << a << endl;

          c++;
     }

     fout.close();

     return 0;
}
thank you very much for that but still nothing is been printing in the text file

i have opened the text file and still nothing
Well probably you are missing something, because that code works perfectly. This is the txt file that is produced:


biggfgfdgdfgfdgdfgdf
0
325.8
1
326.396
2
326.991
3
327.585
4
328.178
5
328.77
6
329.361
7
329.951
8
330.539
9
331.127
10
331.713

...
system("notepad.exe new.txt");

has fixed

thank you
Ok, but it is strange... fout.open should automatically create a new file, il big.txt does not exist.
Same if you try fout.open("big.txt", fstream::out);?

P.S. Using system calls is rarely a good idea...
Last edited on
i works much better with fout.open("big.txt", fstream::out)

thank you very much :-)
#include <iostream>
#include <fstream>
#include <cmath>

using namespace std;

int main()

{
ofstream fout;
fout.open("new.txt");
fout << "hellooo" << endl;
system("notepad.exe new.txt");
fout.open("new.txt", fstream::out);

float a, c, d;
c = 0;
while (c < 101) {
d = (5 * ((c * 1.8) + 32) + 2297) / 2457;
a = 325.8 * sqrt(d);
// print on the screen (console)
cout << c << endl << a << endl;

// print on the file
fout << c << endl << a << endl;

c++;
}

fout.close();

return 0;
}
sorry to bother again but its now not printing again, i have used
system("notepad.exe new.txt"); and it will only a text file and a text file but not print




fout.open("new.txt", fstream::out) doesn't open any text file

i did at first but not now???
I saw you have marked this problem as solved: is everything working properly now?
yes i have it working thanks

but i have issue with a new probelm
Ok!
Topic archived. No new replies allowed.