cancel
Showing results for 
Search instead for 
Did you mean: 

How to create a text file in a function generated by touchgfx?

BSlak.1
Associate

Hello,

I am trying to create a text file after clicking on a button through a virtual function. Has anyone ever done that?

The goal is to save some information entered by the user in a text file and to display it in the UI and access this text file later on through another program to read what has been entered in touchgfx.

Thanks

The code written to create the file (function is called when we click on the button ZSave):

void PositionScreenView::ZSaveButtonClicked()

    {

    fstream test;

    test.open("C:/TouchGFXProjects/UIV1/test.txt",ios::in | ios::out);

    test << "Hello"<<endl;

    

    if (test.is_open()){

       touchgfx_printf("file is open");

 }

  test.close();

}

2 REPLIES 2
Martin KJELDSEN
Chief III

You can use the standard library in TouchGFX applications, but TouchGFX is not required to know anything about various libraries in order to render frames. It's up to you as the application developer to decide what you want to use in your program and consider the cost in code size when you have to run on a perhaps limited hardware platform.

fstream is a part of the standard library, so just use it accordingly:

#include <fstream>
 
using namespace std;

Thank you for taking the time to answer.

We are doing exactly as you wrote. We don't have any errors when running the simulator, but no .txt file is created when it runs. We have certain values saved in some int variables and we are looking to write these in a text file when clicking a "save" button we created.