weird behavior of stringstream and RecordWriter (c++ experts, please help)

91 views
Skip to first unread message

Chenyun Dai

unread,
Mar 6, 2014, 4:49:57 PM3/6/14
to c-cp...@googlegroups.com
Hi C++ experts,

I have a weird behavior of my c++ code:

File* csv_file = File::OpenOrDie(FLAGS_tagless_csv_output_file, "w");
  RecordWriter csv_writer(csv_file);
  while (database_->NextResult()) {
    int64 attribute_id = database_->GetInt64(0);
    int64 owner_account_id = database_->GetInt64(1);
    int64 client_account_id = database_->GetInt64(2);
    stringstream output_line;
    output_line << attribute_id << "," << owner_account_id << ","
                << client_account_id << "\n";
    LOG(INFO) << output_line.str();
    string test = output_line.str();
    csv_writer.Write(test);
  }
  CHECK(csv_writer.Close());
  // Ensure query executed successfully.                                                                                     
  CHECK(database_->Finish());


the above code compiled successfully.

However,

File* csv_file = File::OpenOrDie(FLAGS_tagless_csv_output_file, "w");
  RecordWriter csv_writer(csv_file);
  while (database_->NextResult()) {
    int64 attribute_id = database_->GetInt64(0);
    int64 owner_account_id = database_->GetInt64(1);
    int64 client_account_id = database_->GetInt64(2);
    stringstream output_line;
    output_line << attribute_id << "," << owner_account_id << ","
                << client_account_id << "\n";
    LOG(INFO) << output_line.str();
    csv_writer.Write(output_line.str());
  }
  CHECK(csv_writer.Close());
  // Ensure query executed successfully.                                                                                     
  CHECK(database_->Finish());
  return true;

won't work with following compilation error:

./file/base/recordio.h:1401:3: error: implicit instantiation of undefined template 'ERROR_TYPE_MUST_BE_POD<false>'
  ENFORCE_POD(T);
  ^
./base/type_traits.h:418:14: note: expanded from macro 'ENFORCE_POD'
           = sizeof(ERROR_TYPE_MUST_BE_POD<                               \
             ^
./file/base/recordio.h:884:12: note: in instantiation of function template specialization 'RecordWriter::DispatchWrite<std::basic_string<char> >' requested here
    return DispatchWrite(value, &value);
           ^
contentads/usertargeting/dashboard/tagless/tagless-dashboard-extraction.cc:82:16: note: in instantiation of function template specialization 'RecordWriter::Write<std::basic_string<char> >' requested here
    csv_writer.Write(output_line.str());
               ^
./base/type_traits.h:414:30: note: template is declared here
template <bool IsPod> struct ERROR_TYPE_MUST_BE_POD;
                             ^
1 error generated.


why this error exits? Does it have anything to do with the difference between std::string and google3 string????? If so, how to avoid?

Cheers,
Chenyun
Reply all
Reply to author
Forward
0 new messages