Note that there are some explanatory texts on larger screens.

plurals
  1. POMVS C++ error : string subscript out of range
    primarykey
    data
    text
    <p>I want to solve following task :</p> <p>There is given a text file "pesel.txt", which contains 150 national identities. Each line contains one national identity, which is a 11-digital number. First two digits from the left determine year, which a person was born in, next two digits determine month and next two determine day. </p> <p>To shorten :</p> <p>digits 0-1 = year digits 2-3 = month digits 4-5 = day digits 6-11 = determine something else, what is not important here</p> <p>I need to read the file, check how many people were born in december. I am trying to this in the following way :</p> <ul> <li>read each line until end of file is reached</li> <li>at each line I check whether third character in the string equals 1 and if fourth character equals 2, if yes I increment variable, that is my counter for people born in december, else next loop iteration is executed</li> </ul> <p>Here is the code :</p> <pre><code>int _tmain(int argc, _TCHAR* argv[]) { ifstream file( "C:\\Kuba\\Studia &amp; Nauka\\MATURA XDDD \\INFA\\1\\Dane_PR\\pesel.txt" ); string line; int bornInDecember=0; if( !file.is_open() ){ cout &lt;&lt; "Cannot read the file." &lt;&lt; endl ; }else{ while( file.good() ){ getline( file, line ); if( line[2] == '1' &amp;&amp; line[3] == '2' ){ bornInDecember++ ; // 0-1 year, 2-3 month, 4-5 day } } cout &lt;&lt; "Amount of people born in december : "&lt;&lt; bornInDecember&lt;&lt; endl; file.close(); } system("pause"); return 0; } </code></pre> <p>the problem is that I get the following error and I've no idea why..</p> <p><a href="http://img10.imageshack.us/i/mvserr.png/" rel="nofollow">http://img10.imageshack.us/i/mvserr.png/</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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