Skip to main content
GameDev.net gamedev.net
🔒 Locked

Outputting to a file

Started by dsm1891 Aug 24, 2015 at 7:57 AM 18 replies 6.7k views
Original Post
dsm1891
dsm1891

So, Here I am reading in this Json file and manipulating the values, and I get to a point where I need to see the output... (admittedly I should have done this earlier)

I try (C++)


  std::fstream fs;
  fs.open ("test.txt", std::fstream::in | std::fstream::out | std::fstream::app);

  fs << " more lorem ipsum";

  fs.close();

hmm, strange, not working.

I try ofstream, just to make sure.


ofstream myfile;
  myfile.open ("example.txt");
  myfile << "Writing this to a file.\n";
  myfile.close();

uh... still no file.


char filename[]="example.txt";
FileStream *fs = new FileStream(filename, FileMode::Create, FileAccess::Write);
fstream *fs =new fstream(filename,ios::out|ios::binary);
fs->write("ghgh", 4);
fs->close();

ok... this is annoying me now!

I try absolute paths, on all the files above.

nadda.

Hmm maybe the folder is funky and doesn't allow writing to files, so I try c:\public\Desktop

Still nothing.

Any guesses of what was wrong?

Answer:

[spoiler]my antivirus was blocking me from creating a file sad.png [/spoiler]

Mobile Developer at PawPrint Games ltd. (Not "mobile" as in I move around a lot, but as in phones, mobile phone developer) (Although I am mobile. no, not as in a babies mobile, I move from place to place) (Not "place" as in fish, but location.)
TheComet
TheComet

Reminds me of the time my antivirus decided to delete all DLL files in my python site-packages while I was debugging. "Unable to call function: Function was deleted from your computer"

"I would try to find halo source code by bungie best fps engine ever created, u see why call of duty loses speed due to its detail." -- GettingNifty
aeroKittens
aeroKittens

i guess its a case of "catch 11" (younger sibling to catch 22) here. Without anti-virus dangerous things happen to your system, with anti-virus stupid things happen to your system. I guess you will prefer stupid things to dangerous things

I'm kind of a novice sometimes, complete noob wub.png - Recently, actually a day ago, I saw a strange program "COM surrogate" running on my system. I googled it and discovered its a dangerous virus. I had listened sometimes ago to the good guys of this forum that anti-virus are more of a pain than anything (and seriously slowing you system down), ... and it is not needed as long as windows defender is always on. So i removed my antivirus and always made sure windows defender is on

So despite this how did "COM surrogate" get on to my system? I still don't know how to remove it yet ... despite my efforts

So i guess I got to get my Avast back, yeah stupid things would happen but at least dangerous things would be prevented

(and BTW if anyone knows how i can get rid of "COM surrogate" please let me know .... smile.png )

can't help being grumpy... Just need to let some steam out, so my head doesn't explode... 
Zaoshi Kaba
Zaoshi Kaba

"COM surrogate" is dllhost.exe and part of your OS. For example, explorer.exe uses "COM surrogate" to generate thumbnails, that way if something goes wrong and crashes your explorer won't die.

Although I cannot deny that some viruses are able to use it.

aeroKittens
aeroKittens

"COM surrogate" is dllhost.exe and part of your OS. For example, explorer.exe uses "COM surrogate" to generate thumbnails, that way if something goes wrong and crashes your explorer won't die.
Although I cannot deny that some viruses are able to use it.

Oops!

thanks for letting me know. Weird though that its so associated with a virus when you google it

Said i was a noob didn't i?

can't help being grumpy... Just need to let some steam out, so my head doesn't explode... 
MarkS_
MarkS_

Several years ago, I was using a Mac emulator to access an old drive to retrieve old programming archives. I had to buy a SCSI card and everything to get this to work. Avast! decided that the emulator files containing the drive contained a virus and deleted them all.angry.png Fortunately I still had the drive and could retrieve the files... again... but it was annoying. Since I had the emulator up and running, I ran Disinfectant, a 68000-based Mac antivirus program, on the physical drive. No viruses... dry.png

Servant of the Lord
Servant of the Lord

My favorite was when running a tiny ORPG game with a few other devs, with a userbase of only 20 users.

Norton Antivirus decided to mock our efforts:

e868e15b70.png

wintertime
wintertime

I read more often than I remember that Avast randomly deletes stuff from your HDD. You might want to switch to something better.

Avira was not doing this when I used it, though you might want to check all options to be sure.

Servant of the Lord
Servant of the Lord

I read more often than I remember that Avast randomly deletes stuff from your HDD.

Some versions of Norton does the same (using both blacklists and whitelists), but you can disable the whitelisting.

wintertime
wintertime

They should ask what to do or at least move it into quarantine and give the option to restore it, especially as they depend on heuristics with a high failure rate.

21st Century Moose
21st Century Moose

I saw Symantec delete an Exchange database once. That was exciting.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls. 
rip-off
rip-off
This is why you write error detection and handling early - you can never predict when you'll need it!
Alberth
Alberth

The best case I encountered was while writing a report for some class. We decided to use Word (2 I think, around 1997).

After some hours we were finished (about 15 pages of text), and we wanted to print it.

But for safety, let's save first.....

The file is too big to save, please delete some text and try again

We couldn't stop laughing for 15 minutes!

(There was 20MB free at the disk.)

Luckily, we got it all on paper without accidents, and get a grade for the course.

Needless to say, that was the last time we ever touched Word.

Sik_the_hedgehog
Sik_the_hedgehog




thanks for letting me know. Weird though that its so associated with a virus when you google it

Every single system DLL is labeled a virus on internet =P

Don't pay much attention to "the hedgehog" in my nick, it's just because "Sik" was already taken =/ By the way, Sik is pronounced like seek, not like sick.
Felps
Felps

Solution: Unix and cross-platform code >.>

More better solution for most people:

Don't use mass-market antivirus programs like Norton or McAfee... Use NOD32, Panda, or Kaspersky...

Apparently panda's detection rates are sucky now... Use the other two...

Juliean
Juliean




Solution: Unix and cross-platform code >.>



More better solution for most people:

Don't use mass-market antivirus programs like Norton or McAfee... Use NOD32, Panda, or Kaspersky...

Thats works for you personally but what if you want to share your application? Telling all your users "switch to UNIX or change your antivirus" in case your application fails to run isn't a good option, I sure would not do eigther (antivirus more than switching OS though).

ferrous
ferrous

The default Windows antivirus is pretty decent these days

Servant of the Lord
Servant of the Lord

The default Windows antivirus is pretty decent these days

Yea, that's cause they tossed out the junky Windows Defender, and renamed the good Microsoft Security Essentials as the new Defender, and installed in by default on Win8 and higher.

I still pair it with Spybot Search and Destroy, though.

Felps
Felps

Solution: Unix and cross-platform code >.>



More better solution for most people:

Don't use mass-market antivirus programs like Norton or McAfee... Use NOD32, Panda, or Kaspersky...

Thats works for you personally but what if you want to share your application? Telling all your users "switch to UNIX or change your antivirus" in case your application fails to run isn't a good option, I sure would not do eigther (antivirus more than switching OS though).

You share your application by compiling your cross-platform code I mentioned in the target platform... Obviously... Hopefully you have more than 30 users so McAfee doesn't flag it as suspicious...

edit --- Whoops, sorry McAfee, that one was Norton >.>

Luckless
Luckless

I still have fond memories of the time I was working on something and wanted to double check that I hadn't screwed up my probability calculations on it. Scribbled some notes on some scrap paper, and thought to myself "This really isn't a huge number of total possibilities... I'll just write a few for loops, output everything to a csv file, and then pull it into excel to double check some numbers and get extra data on the project."

Except I was 'slightly' wrong with my math on how many possibilities there were, and had accidentally dropped a variable without noticing.

Coded it up and then noticed I was late for dinner with some friends or something, so hit Go and wandered off for food.

came back a few hours later, and it was still chugging away... Then windows crashed...

Error, bounds, and size checking: Always a good thing, no matter how 'quick this bit of one time code' will be...

Old Username: Talroth
If your signature on a web forum takes up more space than your average post, then you are doing things wrong.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.