Fstream doesnt receive input(?)

closed account (L3ApX9L8)
1
2
3
4
5
6
7
8
9
	fstream Gated(nameToCheck,ios::in);
	if (Gated.fail())	//File is created
	{	
		cout << "blahblahblah, " << ask4Id.geFileName() << "?\n";
		Gated.open (nameToCheck,ios::out);
		cout << "blahblahblah!\n";
		Gated << "test";
		Gated.flush();
		return 0;


Can someone help me figure why "test" isnt being copied to Gated?
I've tried chaning it in many ways, this is just my latest one, and still cant get it to work...

I know its something to do with this bit of code, because everything else works perfectly, and the file even does get created with the correct name...
I'm not sure exactly what you are trying to do, but this is how I tested your code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <fstream>
#include <iostream>
using namespace std;

int main()
  {
  const char nameToCheck[] = "fooey.txt";

  fstream Gated(nameToCheck,ios::in);
  if (Gated.fail())      // Create the file since it didn't exist
    {
    Gated.clear();  // (don't forget to clear all error flags)
//    cout << "blahblahblah, " << ask4Id.geFileName() << "?\n";
    Gated.open (nameToCheck,ios::out);
    cout << "blahblahblah!\n";
    Gated << "test";
    Gated.flush();
    }

  return 0;
  }

It works fine for me. Can you give more information about what exactly you are trying to do?
Last edited on
closed account (L3ApX9L8)
Actually, you solved my problem =p
it seems i had forgotten to clear the error flags, and for some reason that didnt allow me to copy "test" into the file...

Thanks, at last i can continue with the code (and with the learning)~
Topic archived. No new replies allowed.