Home:ALL Converter>Deleted function std basic_stringstream in linux with g++

Deleted function std basic_stringstream in linux with g++

Ask Time:2018-06-19T18:45:36         Author:cht_usr

Json Formatter

I've written the following in windows on Qt IDE and when I run it, it works well, however when I tried to run it on centOS with, I want to run code using threads, in which I'm just tring to load a CSV file and write the results within it in centos envirements

g++ -std=gnu++11 main.cpp -o main

I get the errors

does any solution to this issue ?

code

#include <iostream> // for standard I/O
#include <string>   // for strings
#include <iomanip>  // for controlling float print precision
#include <sstream>  // string to number conversion

#include <ctime>
#include <future>
#include <fstream>
#include <string>

/*
* 
* error This file requires compiler and library support for the ISO C++ 2011 standard. 
* This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options. 
*
*/

using namespace std;

stringstream processing (int x,int id) {

    std::cout << "Calculating. Please, wait...\n";
    stringstream cvsStream;
    for(int i = 0 ; i < x ; ++i){
        cvsStream <<i<<","<<i<<","<<i<<","<<i<<"\n";
        cout <<id<< " / "<<i<< endl;
    }
return cvsStream;
}

int main(int argc, char *argv[])
{
    string filename = "OutputFile.csv";
    ofstream myfile;
    stringstream cvsStream;

    myfile.open(filename);
    // If file does not exist, Create new file
    if (!myfile )
    {
        cout << "Cannot open file, file does not exist. Creating new file..";
        myfile.open(filename,  fstream::in | fstream::out | fstream::trunc);
        myfile <<"\n";
    }
    // open csv file
    cvsStream <<" AD_ID "<<","<<"Starts at "<<","<<"At_Frame"<<","<<"Ends at "<<"\n";
    myfile << cvsStream.str();
    cvsStream.str("");

    auto outputRslt1 = std::async (processing,1000,1);
    auto outputRslt2 = std::async (processing,1000,2);
    auto outputRslt3 = std::async (processing,1000,3);

    stringstream rsltThread1 = outputRslt1.get();
    stringstream rsltThread2 = outputRslt2.get();
    stringstream rsltThread3 = outputRslt3.get();

    // close csv file
    myfile << rsltThread1.str();
    myfile << rsltThread2.str();
    myfile << rsltThread3.str();

    myfile.close();


    return 0;
}

errors

main.cpp: In function ‘std::stringstream processing(int, int)’:
main.cpp:22:8: error: use of deleted function ‘std::basic_stringstream<char>::basic_stringstream(const std::basic_stringstream<char>&)’
return cvsStream;
In file included from main.cpp:4:0:
/usr/include/c++/4.8.2/sstream:502:11: note: ‘std::basic_stringstream<char>::basic_stringstream(const std::basic_stringstream<char>&)’ is implicitly deleted because the default definition would be ill-formed:
 class basic_stringstream : public basic_iostream<_CharT, _Traits>

Author:cht_usr,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/50926506/deleted-function-std-basic-stringstream-in-linux-with-g
yy