0

I have a function TransformString(wchar_t* inputString,...) that modifies inputString, which somewhere along the way calls helper function Help(wstring* string).

I would like to pass wchar_t* inputString to Helper function so that function can modify it. What's the best way to do it?

  • In general, you would create a `wstring` initialised with `inputString` and pass it to your helper function. However all this would do is modify your temporary `wstring` - to propagate the changes back to your original `inputString` depends on how that was created - you would need to check that it is large enough to contain the new string to avoid buffer overflows. You might want to consider refactoring `TransformString` to work on a `wstring` to begin with. – Jonathan Potter Sep 08 '14 at 19:40
  • I was scared that was the only answer. Was hoping there is a pointer transformation I could do in order to avoid refactoring. – user2775761 Sep 08 '14 at 19:48
  • While at it, consider returning the string instead or at least using references. – Ulrich Eckhardt Sep 08 '14 at 20:42
  • Here is a very similar question, with stome relevant answers to you (instead of a helper function, it considers the case of a win api function): http://stackoverflow.com/questions/25715127/c-using-stdstring-stdwstring-as-a-buffer – Christophe Sep 08 '14 at 21:47

0 Answers0