ページ 11

C++でテキストを分割する処理で詰まっています

Posted: 2011年2月14日(月) 10:28
by basuku

コード:

void divide(const std::string& filename, int lineSize)
{
  std::ifstream fin(filename.c_str());

  int fileCount = 1;
  int lineCount = 1;

  std::stringstream stream;
  stream << "a_" << fileCount << ".txt";
  std::ofstream* fout = new std::ofstream(stream.str().c_str());
  while(!fin.eof()){
	char line[256];
	fin.getline(line, sizeof(line));
	(*fout) << line << std::endl;

	++lineCount;
	if (lineCount > lineSize) {
	  fout->close();
	  delete fout;

	  ++fileCount;
	  lineCount = 1;
	  stream.str("");
	  stream << "a_" << fileCount << ".txt";
	  fout = new std::ofstream(stream.str().c_str());
	}
  }

  fout->close();
  delete fout;
}


で、
std::stringstream stream;
の場所でクラステンプレートを使用するにはテンプレート引数リストが必要ですと
エラーが出るんですが、対応方法がよくわかりません。
よろしくお願いします。
環境:WindowsXP、VisualC++2008ExpressEdition

Re: C++でテキストを分割する処理で詰まっています

Posted: 2011年2月14日(月) 10:41
by softya(ソフト屋)
推測ですが、
#include<sstream>
が足らないんじゃないでしょうか?

Re: C++でテキストを分割する処理で詰まっています

Posted: 2011年2月14日(月) 10:48
by basuku
追加したらコンパイルが通りました。
ありがとうございます。

Re: C++でテキストを分割する処理で詰まっています

Posted: 2011年2月14日(月) 11:09
by basuku
解決しました、ありがとうございます。