Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #7340
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.glorb.com!news-out.readnews.com!news-xxxfer.readnews.com!panix!panix.com!mrbrklyn |
|---|---|
| From | Ruben Safir <mrbrklyn@panix.com> |
| Newsgroups | comp.lang.c++ |
| Subject | Re: reading from a temp file |
| Date | Sat, 2 Jul 2011 00:47:27 +0000 (UTC) |
| Organization | PANIX Public Access Internet and UNIX, NYC |
| Lines | 112 |
| Message-ID | <iulpqv$n0n$1@reader1.panix.com> (permalink) |
| References | <iuc3me$nam$2@reader1.panix.com> <96ti78FuacU2@mid.individual.net> <c172014c-298e-4077-a806-57e2dab95626@m22g2000yqh.googlegroups.com> |
| NNTP-Posting-Host | panix2.panix.com |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | quoted-printable |
| X-Trace | reader1.panix.com 1309567647 23575 166.84.1.2 (2 Jul 2011 00:47:27 GMT) |
| X-Complaints-To | abuse@panix.com |
| NNTP-Posting-Date | Sat, 2 Jul 2011 00:47:27 +0000 (UTC) |
| User-Agent | tin/1.8.3-20070201 ("Scotasay") (UNIX) (NetBSD/5.1 (i386)) |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.c++:7340 |
Show key headers only | View raw
Michael DOUBEZ <michael.doubez@free.fr> wrote:
> On Jun 28, 10:37 am, Ian Collins <ian-n...@hotmail.com> wrote:
>> On 06/28/11 08:34 PM, Ruben Safir wrote:
>>
>> > any clue why this isn't retrieving the contents of the temp file
>>
>> > Question Deck::create_question(WINDOW* menu_win, std::ostream&os ,std::istream&in ){
>>
>> > char default_editor[20000] = "vi ";
>> > char * editor;
>> > char tmp[4096];
>> > char path[] = "/tmp/fileXXXXXX";
>>
>> Why don't you use strings?
>
> because mkstemp expect a char* that is modified. A solution is to
> using std::vector<char> instead.
>
std::vector<char> or std::vector<char *> ?
>>
>> > int fd;
>> > fd = mkstemp(path);
>> > editor = getenv("EDITOR");
>> > if (editor == NULL){
>> > editor = default_editor;
>> > }
>>
>> > strcat(editor, path);
>> > char quest_prompt[] = "Edit Your Question";
>> > .....
>> > std::string input_q, input_a;
>> > while( ( c=wgetch(quest_win) ) ){
>> > if ( (c == 10) ){
>> > def_prog_mode();
>> > endwin();
>>
>> What are these?
>>
>> > system(editor);
>> > reset_prog_mode();
>>
>> and this?
>
> A gnu extension for building a filebuf from a file descriptor. IMO
> closing the fildescriptor returned and using a simple ifstream with
> path, would be less trouble.
Those above are part of ncures.h, but those below as was you describe.
>
> In particular, the openmode are not good: binary will not translate
> carriage return and app is irrelevant in input mode (and input mode is
> missing). Use plain std::ios::in instead.
>
The editor is creating a text file so you might be correct, but I don't
think I want carriage returns altered or interpreted, just eventually
dumped into a data file at 4096 bit clips. And I don't want to deal
with deliminators or terminators on input, or output, which is a problem
with getline and getchar. I want them included in the input stream,
whole.
> I don't know how it works in conccurent access, stdio_sync_filebuf<>
> may be required here (with minimal buffer size in parameter for good
> measure).
>
It didn't have trouble with two seperate streams from the same fd. I
did have trouble using one stream for both in and out.
>> > __gnu_cxx::stdio_filebuf< char> tmpfile_buf(fd, std::ios::binary|std::ios::app);
>>
>> What's one of those?
>>
>> > std::istream is(&tmpfile_buf);
>> > is.seekg(0, std::ios::beg);
>
> seekg is not guaranteed to work
>
Upon input? It didn't work away. I thought maybe I as set to the end
of the stream but it didn't like binary mode at all, and the eof bits
behaved as I expected so I can only guess that it was behaving OK.
>> > while(is){
>> > is.read( tmp, 4096);
>> > std::cerr<< "What did we read"<< tmp<< std::endl;
>> > input_q = tmp;
>> > }
>> > tmpfile_buf.close();
>
> Note that you can dump the content of a file with:
> std::err<<is.rdbuf();
>
I want a guaranteed chunk of 4096, no greater.
>> > break;
>> > }
>> > }
>> > remove(path);
>>
>
> --
> Michael
Back to comp.lang.c++ | Previous | Next — Previous in thread | Find similar | Unroll thread
reading from a temp file Ruben Safir <ruben@mrbrklyn.com> - 2011-06-28 08:34 +0000
Re: reading from a temp file Ian Collins <ian-news@hotmail.com> - 2011-06-28 20:37 +1200
Re: reading from a temp file jt@toerring.de (Jens Thoms Toerring) - 2011-06-28 09:55 +0000
Re: reading from a temp file Ruben Safir <ruben@mrbrklyn.com> - 2011-06-28 12:32 +0000
Re: reading from a temp file jt@toerring.de (Jens Thoms Toerring) - 2011-06-28 13:54 +0000
Re: reading from a temp file Ruben Safir <mrbrklyn@panix.com> - 2011-07-01 05:14 +0000
Re: reading from a temp file Michael DOUBEZ <michael.doubez@free.fr> - 2011-07-01 00:54 -0700
Re: reading from a temp file Michael DOUBEZ <michael.doubez@free.fr> - 2011-07-01 01:20 -0700
Re: reading from a temp file Ruben Safir <mrbrklyn@panix.com> - 2011-07-02 00:47 +0000
csiph-web