title: C++ equivalent of python's expandtabs() function?
body: <p>I need to implement the C++ equivalent of the expandtabs() function. Can someone help me with converting this code to C++?</p>
  
  <pre><code>def expandtabs(string, n):
      result = ""
      pos = 0
      for char in string:
          if char == "\t":
              # instead of the tab character, append the
              # number of spaces to the next tab stop
              char = " " * (n - pos % n)
              pos = 0
          elif char == "\n":
              pos = 0
          else:
              pos += 1
          result += char
      return result
  </code></pre>
  
  <p>This is what I have:</p>
  
  <pre><code>std::string ExpandTabs(const std::string &amp;str, int tabsize =4){
  
    std::string ReturnString = str;
    std::string result = " ";
    int pos = 0;
  
    for(std::string::size_type i = 0; i &lt; ReturnString.size(); ++i) {
      if (ReturnString[i] == '\t'){
        int spaces = tabsize - pos % tabsize ;
        ReturnString.append(" ", spaces);
        pos = 0;
      }
      else{
        pos+=1;
      }
  
  }
    return ReturnString;
  
  </code></pre>