This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

LCDK fstream issue

Hello,


I am having a problem reading from a text file using fstream on the LCDK with bios 6.35.04.50.  Two approaches are shown below:

int data[2];

Approach A:

    FILE *fp = fopen("C:\\filename.txt","r"); // read mode
    fscanf(fp,"%d %d",&data[0],&data[1]);
    printf("data = %d, %d\n",data[0],data[1]);
    fclose(fp);

Approach B:


    std::fstream ifs("C:\\filename.txt", std::ios::in);
    ifs >> data[0];
    ifs >> data[1];
    std::cout << "data = " << data[0] << ' ' << data[1] << std::endl;
    ifs.close();

Approach A works fine.  Using Approach A and Approach B (in succession) works fine.  Using Approach B alone produces no output to console.

All necessary header files have been included.

Any help is greatly appreciated. Thank you.

  • Hi Michael,

    Welcome to the TI E2E forum. I hope you will find many good answers here and in the TI.com documents and in the TI Wiki Pages. Be sure to search those for helpful information and to browse for the questions others may have asked on similar topics.

    There are quite a few different forums on E2E. This device forum is good for device-specific or hardware/driver questions. The C/C++ Compiler Forum is good for issues with the build tools and the Run-Time Support library. The Code Composer Forum is good for issues with the debugger and its capabilities.

    1. As the "C" code works, the "C++" code is also supposed to work. It seems to me this is not a device specific query but more of a C++ programming issue.

    2. My suggestion for you is to debug line by line using "step over" and check using whether the file, "filename.txt" is successfully opened in C++. Whether the datas are read into the array data[0] and data[1] ? Whether it is not able to do cout..e.t.c,

    3. What do you mean by "produces no output? If so, are you able to build the C++ code successfully? If not, what is the error you got? What happens when you run the program connecting the target?

    Let us know how it goes and what you learn about it.

     

    Regards,

    Shankari

    -------------------------------------------------------------------------------------------------------

    Please click the Verify Answer button on this post if it answers your question.
    --------------------------------------------------------------------------------------------------------