2 Replies Latest reply on Apr 28, 2011 12:37 PM by 858326

    CC Compiler barfs when replacing string using istreambuf_iterator.

      Hi All,

      I am a noobie to Solaris.

      The following piece of code when compiled with g++ works fine.

      But Solaris CC compiler barfs.
      #include <iostream>
      #include <fstream>
      #include <iterator>
      #include <string>
      using namespace std;
      std::string stlString("test for string.assign() method");
      int main () {
        filebuf fb;
        fb.open ("test.txt",ios::in);
        istream is(&fb);
        istreambuf_iterator<char> itr(is);
        istreambuf_iterator<char> end;
        std::cout << "before : " << stlString << std::endl;
        stlString.assign(itr, end);
        //while ((itr != end) && (*itr != '\n')) stlString+=*itr++;
        std::cout << "after : " << stlString << std::endl;
        return 0;
      $ cat test.txt
      this is a sample file
      $ g++ -m32 -Wall -g istreambuf.cc
      $ ./a.out
      before : test for string.assign() method
      after : this is a sample file
      $ CC -m32 -g istreambuf.cc -library=iostream
      "istreambuf.cc", line 20: Error: Could not find a match for std::string::assign(std::istreambuf_iterator<char, std::char_traits<char>>, std::istreambuf_iterator<char, std::char_traits<char>>) needed in main().
      1 Error(s) detected.
      Any help is appreciated.

      I need the code to be compiled on both (CC and g++).

      Any help is appreciated.

      Thanks in advance,