Matan L.
Matan L.

Reputation: 339

How to use stringstream in Xilinx SDK?

When trying to add

#include <sstream>

which is needed for stringstream, I get several errors, the following included:

expected ';' at end of input
expected '}' at end of input
macro "str" requires 2 arguments, but only 1 given

How to enable using stringstream ?

Upvotes: -1

Views: 765

Answers (2)

Jose Mateos
Jose Mateos

Reputation: 1

I just signed up just to answer this question.

I went through this post some time ago and used the solution posed, even though I didn't like it very much. It was a mistake.

This solution can cause deadlock of the system after some time in a random way, very difficult to debug.

I propose the following solution:

  1. create the file "compatible_sstream.h":

    #pragma push_macro("str")
    #undef str
    #include <sstream>
    #pragma pop_macro("str")
    
  2. replace #include <sstream> with #include "compatible_sstream.h" in all the other files.

  3. wrap all calls to std::ostringstream::str in parentheses as in the example:

    std::ostringstream foo()
    {
    // ...
    }
    
    void main()
    {
    // ...
    std::cout << (foo().str)() << std::endl;
    // ...
    }
    

Apologies in advance if I have not followed any of the posting rules correctly.

Upvotes: 0

Matan L.
Matan L.

Reputation: 339

This is a bug in the Xilinx SDK.

You need to undef a macro named str.

Replace

#include <sstream>

with

#undef str
#include <sstream>

Credit: This method was proposed by sparks333 and can be found here: https://forums.xilinx.com/t5/Embedded-Development-Tools/Error-with-Standard-Libaries-in-Zynq/td-p/450032

Upvotes: 3

Related Questions