Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   ofstream (standard C++ file output) not working (http://www.chiefdelphi.com/forums/showthread.php?t=79548)

davidalln 19-01-2010 18:11

Re: ofstream (standard C++ file output) not working
 
Did you or anyone else successfully get a log running on their cRio? We are trying to do something similar, and we have had consistent success with creating the file but very spotty success when writing to it (depending on where the lines are added in the code). Sometimes it works sometimes it doesn't.

slavik262 25-01-2010 14:37

Re: ofstream (standard C++ file output) not working
 
I know this is quite a bump, but now I'm even having problems using C file I/O with FILE* pointers. I've called Priv_SetWriteAllowed(1) and still weird stuff happens. Sometimes things work fine, but there's a boat load of issues most of the time:
  • While some files write fine, others don't write at all, and still others write nothing but whitespace.
  • fwrite() reformats strings for some bizarre reason. Example: I wanted to print some formatted data into a .csv (comma seperated value) file. I used sprintf() to print some floats with some commas, carraige returns, and line feeds. Calling printf() on the string created with sprintf() yields what I would expect, but when I write the exact same string to the file with fwrite(), every float is smaller by two orders of magnitude.

Does anybody have any idea what could be causing this? It's making things very difficult and I can't imagine why it would be happening.

TheDominis 25-01-2010 22:16

Re: ofstream (standard C++ file output) not working
 
I've found that some parts of the STL do not work with well/at all Wind River. I tried to use std::fstream to store some packet data, but had to use c-style file I/O for it to work.

slavik262 26-01-2010 00:15

Re: ofstream (standard C++ file output) not working
 
Quote:

Originally Posted by TheDominis (Post 906907)
I've found that some parts of the STL do not work with well/at all Wind River. I tried to use std::fstream to store some packet data, but had to use c-style file I/O for it to work.

C-style file I/O isn't working for me at all either... :confused:

TheDominis 26-01-2010 13:35

Re: ofstream (standard C++ file output) not working
 
Quote:

Originally Posted by slavik262 (Post 906981)
C-style file I/O isn't working for me at all either... :confused:

Interesting. What permissions are you using? I used "w".

slavik262 26-01-2010 16:37

Re: ofstream (standard C++ file output) not working
 
I was using w. I guess I could try wb or w+, but I was just writing text...

byteit101 31-01-2010 19:57

Re: ofstream (standard C++ file output) not working
 
I (finally!) got a chance to test this again.
code (in auto)
Code:

ofstream txt;
txt.open("test.txt");
txt<<"IT WORKS!!!"<<endl;

for some reason, (without the priv_setwrite stuff) it worked 2 of the three times i tested it. No difference except different flies

slavik262 01-02-2010 10:04

Re: ofstream (standard C++ file output) not working
 
Exactly! That's what's so odd about it. It's not even that it doesn't work, but that it works inconsistantly with no changes except filenames. I have no idea what could be causing the problem. It's so frustrating. :mad:

On the note of standard library things failing, does anyone have issues with std::cout? printf() works fine, but cout refuses to print a thing. I'm using the VxWorks Target Console in WindRiver.

byteit101 01-02-2010 15:10

Re: ofstream (standard C++ file output) not working
 
Quote:

Originally Posted by slavik262 (Post 911086)
Exactly! That's what's so odd about it. It's not even that it doesn't work, but that it works inconsistantly with no changes except filenames. I have no idea what could be causing the problem. It's so frustrating. :mad:

On the note of standard library things failing, does anyone have issues with std::cout? printf() works fine, but cout refuses to print a thing. I'm using the VxWorks Target Console in WindRiver.

cout is mis-directed most of the time (strange), but cerr is working fine for us. we rdbuf it though,
streambuf *cerbuf=cerr.rdbuf();
cout.rdbuf(cerbuf);

EDIT: now that I think about it, the getting started guided called it printf/cout output. strange they did not get it working with that title

jhersh 02-02-2010 18:10

Re: ofstream (standard C++ file output) not working
 
Quote:

Originally Posted by slavik262 (Post 911086)
On the note of standard library things failing, does anyone have issues with std::cout? printf() works fine, but cout refuses to print a thing. I'm using the VxWorks Target Console in WindRiver.

This is a known issue with the Target Console. cout does not work, but printf does. If you are using the Serial console, I believe the cout will work. Probably with NetConsole as well, but I haven't tried it. I tend to completely avoid things that work "in certain cases".

It never bothered me, though since I like to format the things I print and inserting magic format objects feels like a lame hack compared to a concise format string. Oh well... preferences, I guess.

-Joe

jhersh 02-02-2010 18:14

Re: ofstream (standard C++ file output) not working
 
Quote:

Originally Posted by byteit101 (Post 910849)
...for some reason, (without the priv_setwrite stuff) it worked 2 of the three times i tested it. No difference except different flies

This sounds like a race condition to me. I know there are several files in the vision code (and probably others) that call Priv_SetWriteFileAllowed in some cases. Perhaps in the test runs where it works, that code happened to win the race against your test code.

-Joe

slavik262 03-02-2010 08:37

Re: ofstream (standard C++ file output) not working
 
I agree that behavior like this sounds like a race condition, but why would a race occur for a file stream, especially to a file that's not used by any other part of the system?

jhersh 03-02-2010 15:11

Re: ofstream (standard C++ file output) not working
 
Quote:

Originally Posted by slavik262 (Post 912413)
I agree that behavior like this sounds like a race condition, but why would a race occur for a file stream, especially to a file that's not used by any other part of the system?

I was under the impression that Priv_SetWriteFileAllowed was a global system setting, not associated with any particular task or file handle. If the fopen is racing with Priv_SetWriteFileAllowed, it doesn't matter who is calling each of them.

-Joe

slavik262 03-02-2010 18:06

Re: ofstream (standard C++ file output) not working
 
Quote:

Originally Posted by jhersh (Post 912662)
I was under the impression that Priv_SetWriteFileAllowed was a global system setting, not associated with any particular task or file handle. If the fopen is racing with Priv_SetWriteFileAllowed, it doesn't matter who is calling each of them.

-Joe

From my understanding, you call Priv_SetWriteFileAllowed(1) to allow a file write operation and then call fopen() as usual.

jhersh 04-02-2010 02:25

Re: ofstream (standard C++ file output) not working
 
Quote:

Originally Posted by slavik262 (Post 912782)
From my understanding, you call Priv_SetWriteFileAllowed(1) to allow a file write operation and then call fopen() as usual.

Yes... and...

The way I understand it, it enables write access to the filesystem as a whole. In other words, if no one calls it, noone can write to the disk. If anyone calls it, then anyone can write to the disk (or open for write).


All times are GMT -5. The time now is 12:31.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi