vendredi 27 juillet 2018

Stringstream compile error occurs only in linux environment

I wrote a program in C++ using Visual Studio on my desktop. In that environment, the program compiles and executes without error, and the output is exactly as expected.

However, when I try to move my source code to a linux system and compile it, the I encounter errors related to my use of stringstream. The code has the form:

string line;
stringstream ssline;
//initialize line
ssline = stringstream(line) //where the error occurs

I use this assignment operation many times throughout my program, and like I said - I didn't cause any problems when I used Visual Studio to compile. On my linux system, both the gnu compiler and the intel compiler throw the same error, which reads:

ProgramName.cpp:73:12: error: use of deleted function
‘std::basic_stringstream<char>& std::basic_stringstream<char>::operator=
(const std::basic_stringstream<char>&)’
    ssline = stringstream(line);
                ^
In file included from ProgramName.cpp:13:0:
/usr/include/c++/4.8.2/sstream:502:11: note:
‘std::basic_stringstream<char>& std::basic_stringstream<char>::operator=(const std::basic_stringstream<char>&)’
is implicitly deleted because the default definition would be ill-formed:
    class basic_stringstream : public basic_iostream<_CharT, _Traits>

I do not know what to make of this error, nor why it seems to be system dependent. I can rewrite my source code to avoid the use of stringstream, but I would prefer not to. Because again, I know it works on my desktop environment.

I appreciate any help that can be offered in resolving this difficulty. Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire