title: visual C++ string subscript out of range
body: <p>I am stuck with the error &quot;string subscript out of range&quot;. <br />
  After testing, I am pretty sure that it's because of this function, which is used for reading values in a file, but have no idea what's wrong:</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  using namespace std;
  
  string read(string value) {
      ifstream input;
      string line=&quot;&quot;, output=&quot;&quot;;
      size_t pos;
      bool a = true;
      int i = 0;
      input.open(&quot;pg_options.txt&quot;);
      if (!input.is_open()) {
          cout &lt;&lt; &quot;pg_options.txt missing.&quot;;
          return &quot;error&quot;;
      }
      while (getline(input, line)) { //get file lines
          pos = line.find(value);
          if (pos == string::npos) { //if value in line
              while (a == true) {
                  if (line[i] == '=') { //after &quot;=&quot; 
                      i++;
                      break;
                  }
                  else {
                      i++;
                  }
              }
              for (i; line[i] != ' '; i++) {
                  output += line[i]; //put value to output
              }
          }
      }
      input.close();
      return output;
  }
  </code></pre>
  <p>pg_options.txt:</p>
  <pre><code>include_special_characters=true
  include_upper_case=true
  include_lower_case=true
  include_numbers=true
  digits=10
  </code></pre>
  <p><code>cout &lt;&lt; read(&quot;digits&quot;)</code> returns the error mentioned above.</p>