-4

I am trying to create a string array to hold the strings generated by a void function. I am very confused about if or how I can do this. The below code is giving me an error about "no suitable constructor."

getWords("theFile.dat");     // Function to extract list of strings from file       
string wordsList[] = {getWords("theFile.dat")};    // Add strings from function to array

1 Answers1

3

If (as your comment states) the code uses cout to print the strings, then you have no way to capture them and put them in your array. Well, ok, you might be able to, by doing some major/ugly hack that grabs hold of the stdout file descriptor and reads what is written to it, but that would just be ugly beyond words (and most likely would need different platform specific implementations). Just don't go there.

Write your own good function to read the file and return what you need or fix the crap function you've been given.

There's got to be a limit to how much crud (with the risk of introducing more crap/bugs) one has to add to work around broken crap code before fixing or re-implementing/re-factoring it.

Jesper Juhl
  • 28,933
  • 3
  • 44
  • 66