Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.os.linux.development.apps > #170
| From | James Waldby <not@valid.invalid> |
|---|---|
| Newsgroups | comp.os.linux.development.apps |
| Subject | Re: reading a temp file in C++ |
| Date | 2011-06-28 15:58 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <iuctn2$h6o$2@dont-email.me> (permalink) |
| References | <iuc3l7$nam$1@reader1.panix.com> |
On Tue, 28 Jun 2011 08:33:43 +0000, Ruben Safir wrote:
> any clue why this isn't retrieving the contents of the temp file
It appears you create and open a temp file via fd = mkstemp(path);,
then invoke vi via system(editor);, and finally read and print
from fd. I presume that when user saves file and exits vi, that
in effect vi writes a new temp file, renames the original temp file,
and renames the new temp file. If so, fd contents don't change.
> 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";
> 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();
> system(editor);
> reset_prog_mode();
> __gnu_cxx::stdio_filebuf< char> tmpfile_buf(fd,
> std::ios::binary|std::ios::app); std::istream is(&tmpfile_buf);
> is.seekg(0, std::ios::beg);
> while(is){
> is.read( tmp, 4096);
> std::cerr << "What did we read" << tmp << std::endl; input_q = tmp;
> }
> tmpfile_buf.close();
> break;
> }
> }
> remove(path);
--
jiw
Back to comp.os.linux.development.apps | Previous | Next — Previous in thread | Next in thread | Find similar
reading a temp file in C++ Ruben Safir <ruben@mrbrklyn.com> - 2011-06-28 08:33 +0000
Re: reading a temp file in C++ Richard Kettlewell <rjk@greenend.org.uk> - 2011-06-28 09:46 +0100
Re: reading a temp file in C++ James Waldby <not@valid.invalid> - 2011-06-28 15:58 +0000
Re: reading a temp file in C++ jt@toerring.de (Jens Thoms Toerring) - 2011-06-28 21:17 +0000
Re: reading a temp file in C++ ruben safir <ruben@mrbrklyn.com> - 2011-06-30 03:06 +0000
csiph-web