0

I need to create a bunch of different files and I want to name them something like:

"signal1.dat", "signal2.dat", "signal3.dat", ... , "signal100.dat"

This is what I have so far

std::stringstream ss;
std::string out = "signal";
std::string format = ".dat";
std::string finalName;
int TrkNxtSig = 1;

...
[code]  
... 


ss << out << TrkNxtSig << format;
finalName = ss.str();
ofstream output(finalName); 
TrkNxtSig++;

I get this error

     error: no matching function for call to ‘std::basic_ofstream<char, std::char_traits<char> >::basic_ofstream(std::string&)’
/usr/include/c++/4.4/fstream:623: note: candidates are: std::basic_ofstream<_CharT, _Traits>::basic_ofstream(const char*, std::_Ios_Openmode) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/fstream:608: note:                 std::basic_ofstream<_CharT, _Traits>::basic_ofstream() [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/iosfwd:84: note:                 std::basic_ofstream<char, std::char_traits<char> >::basic_ofstream(const std::basic_ofstream<char, std::char_traits<char> >&)

I'm not sure what that error message is telling me. What is wrong?

tshepang
  • 12,111
  • 21
  • 91
  • 136
shaboinkin
  • 171
  • 1
  • 11
  • possible duplicate of [Why don't the std::fstream classes take a std::string?](http://stackoverflow.com/questions/32332/why-dont-the-stdfstream-classes-take-a-stdstring) – Ben Voigt Jul 09 '12 at 15:47
  • 1
    BTW, if you upgrade your compiler it should start working. – Ben Voigt Jul 09 '12 at 15:48
  • 1
    Tags are there so that you don't need to provide them in your title (i.e. remove the `[C++]` from the title). Actual tags are more powerful as they allow for indexing and searching – David Rodríguez - dribeas Jul 09 '12 at 15:56

1 Answers1

2

It's telling you that there's no constructor for ofstream that takes a std::string as parameter.

Use ofstream output(finalName.c_str()); instead.

This has been fixed in C++11. If you're using gcc, try passing it -std=c++0x.

jrok
  • 54,456
  • 9
  • 109
  • 141