Note that there are some explanatory texts on larger screens.

plurals
  1. POC++: std::string problem
    text
    copied!<p>I have this simple code:</p> <pre><code>#include &lt;iostream&gt; #include &lt;fstream&gt; using namespace std; int main(void) { ifstream in("file.txt"); string line; while (getline(in, line)) { cout &lt;&lt; line &lt;&lt; " starts with char: " &lt;&lt; line.at(0) &lt;&lt; " " &lt;&lt; (int) line.at(0) &lt;&lt; endl; } in.close(); return 0; } </code></pre> <p>which prints:</p> <pre><code> 0.000000 0.000000 0.010909 0.200000 starts with char: 32 A 0.023636 0.000000 0.014545 0.200000 starts with char: A 65 B 0.050909 0.000000 0.014545 0.200000 starts with char: B 66 C 0.078182 0.000000 0.014545 0.200000 starts with char: C 67 ... , 0.152727 0.400000 0.003636 0.200000 starts with char: , 44 &lt; 0.169091 0.400000 0.005455 0.200000 starts with char: &lt; 60 . 0.187273 0.400000 0.003636 0.200000 starts with char: . 46 &gt; 0.203636 0.400000 0.005455 0.200000 starts with char: &gt; 62 / 0.221818 0.400000 0.010909 0.200000 starts with char: / 47 ? 0.245455 0.400000 0.009091 0.200000 starts with char: ? 63 ¡ 0.267273 0.400000 0.005455 0.200000 starts with char: � -62 £ 0.285455 0.400000 0.012727 0.200000 starts with char: � -62 ¥ 0.310909 0.400000 0.012727 0.200000 starts with char: � -62 § 0.336364 0.400000 0.009091 0.200000 starts with char: � -62 © 0.358182 0.400000 0.016364 0.200000 starts with char: � -62 ® 0.387273 0.400000 0.018182 0.200000 starts with char: � -62 ¿ 0.418182 0.400000 0.009091 0.200000 starts with char: � -62 À 0.440000 0.400000 0.012727 0.200000 starts with char: � -61 Á 0.465455 0.400000 0.014545 0.200000 starts with char: � -61 </code></pre> <p>Strange... How can I get really the first character of the <code>string</code>?</p> <p>Thanks in advance!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload