What am i missing

So the program is supposed to create a file which it does fine but when it comes to opening hat file back up the program for some reason just skips over it and wont opn it and write to it, could anyone give me some pointers about what I might be missing

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
39
40
41
42
43
44
45
46
47
 #include <iostream>
#include <fstream>
#include <string>

void create();
void write();

using namespace std;

string test;
int name;
string filename;

int main()

{
	cout<< " What would you like to do: (1) write to a file " <<endl;
	cout << "                            (2) make a file" << endl;
	cin >> name;
	switch(name)
	{
	case 1 : cout << "name of file" << endl;
		getline(cin,test);
		write();
		break;
	case 2: create();
		break;
	default: cout << "bye" << endl;
	}


};

void create()
{
  fstream inout;
  inout.open(filename, ios::app);
  inout.close();
}

  void write()
  {
  fstream inout;
  inout.open(filename, ios::out |ios::app);
  inout << test << endl;
  inout.close();
  }
The write() function is the name of a standard "C" low-level function. You should rename it. Also, add some tests of the fstream flags to see perhaps why your code is failing. I'm thinking primarily of the functions that are inherited from ios.
alright I renamed the write() function and I changed the create() function to ofstream and then i changed cin >> name to a getline(cin,name) and everything worked thank you for your input, have a nice day .
Topic archived. No new replies allowed.