0

Put simply, I have a browser widget I'm using in FLTK Gui toolkit which can be loaded using a file like so.

browser::load("textfile.txt");

The problem is I don't want to create a physical text file, just an invisible one so I can use it as an argument for browser::load above. I plan to use this invisible text file by loading it with the values I'm going to place in my browser....then use it like this.

browser::load("invisible_textfile.txt");

Is it possible to do this in C++?

I have already tried using ifstream::rdbuf() which probably has nothing to do with this. I'm not even sure what to call this so I'm just calling it an invisible textfile for now.

I'm using windows 7 64 bit. MinGW compiler.

hyde
  • 60,639
  • 21
  • 115
  • 176
Svetsi
  • 305
  • 1
  • 4
  • 12
  • Do you mean hidden file by invisible? – Manthan Tilva Jul 17 '16 at 07:41
  • If you want to avoid displaying a file in the browser, why can't you just not call browser::load()? – Klitos Kyriacou Jul 17 '16 at 07:50
  • 1
    Misconception there.. What the browser does is it gets the file and displays it's contents in the browser. It can be set to take into account columns to align rows and columns. – Svetsi Jul 17 '16 at 07:58
  • 1
    invisible file, yes.. Like a fstream which doesn't great a file. – Svetsi Jul 17 '16 at 08:00
  • So where do you want this text to be? Embedded in the binary program (often, at least in Qt, called a "resource")? – hyde Jul 17 '16 at 08:03
  • Note that it would be *much* better to show real code in a Stack Overflow question. `browser::load("textfile.txt");` isn't even compilable C++! – hyde Jul 17 '16 at 08:23

2 Answers2

1

It depends a lot on what browser::load() actually does internally, but let's assume that it will look for your filename and load it.

You probably already know how to read / write a standard file (e.g. http://www.cplusplus.com/doc/tutorial/files/). Now, if you just want to hide the file from the user, you can set OS specific hidden flags (e.g. windows). I'm assuming that's not what you actually want to accomplish here. (You could obviously also create a temporary file that you delete again, but it's not an elegant solution either.)

What you might want to use is a named pipe. Under Linux you can create these with mkfifo and then stream content through those file objects.

The general point is, though, unless the browser API allows you to pass it a complete string holding the text file or a stringstream, you will need a file object.

If your only target system is NTFS, there is a good answer on creating virtual files over here: How to create a virtual file?

But in the end, you probably want to create an actual file (in your case probably a temporary one, though). I would recommend placing that file into the systems temporary path.

Community
  • 1
  • 1
Chris
  • 3,245
  • 4
  • 29
  • 53
1

Let's say what you want to add is equivalent of text file like this:

One
Two
Three

But you don't want to have the text file. So one piece of code which would do the same thing is this:

const char *lines[] = { "One", "Two", "Three", 0 };
for(int i = 0 ; lines[i] != 0 ; ++i)
    browser.add(lines[i]);

Documentation link for that overload of add

Please refine your question, or perhaps ask a new question, if you want more help on how to get lines with your data.

hyde
  • 60,639
  • 21
  • 115
  • 176
  • hyde,, did you read svet's question? That's not what she's asking. It's pretty clear that the load method takes a text file.. – domonica Jul 18 '16 at 08:48
  • @domonica As I read the question, OP specifically does not want an actual text file, they want something else. Using a named pipe or something to be able to use load() would be Rube Goldbergian contraption to achieve the result, when there is add() method, which can do it directly. – hyde Jul 18 '16 at 10:48