Note that there are some explanatory texts on larger screens.

plurals
  1. POseekg and tellg miscompatibility
    primarykey
    data
    text
    <p>I am writing a C++ console application. After creating an Matrix with size(int) rowSize and columnSize, I wanted to write the letters in text file to matrix, but while loop never runs because reader's location is -1, and I couldn't take it to 0. Any ideas?</p> <pre><code>void writeText2Vec(ifstream &amp; reader, tmatrix&lt;char&gt; &amp; table){ string s; int length, row = 0, column = 0; //beginning: column and //row ids are set to 0. reader.seekg(0); //reset the pointer to start cout &lt;&lt; reader.tellg(); // it results in -1. while (getline(reader,s)){ //for each line while loop occurs. length = s.length(); for(column = 0; column &lt; length; column++) { table[row][column] = s.at(column); //writing the letter to matrix. } row++; } bool openFile(ifstream &amp; reader, string filename){ reader.open(filename.c_str()); if (reader.fail()){ exit("File cannot be found."); return false; } else { return true; } } bool check(ifstream &amp; reader, int &amp; rowSize, int &amp; columnSize){ //checks for valid characters, if they are //alphabetical or not and for the length. string s; int len = 0, max = 0; while (getline(reader,s)){ //runs for every line. rowSize++; //calculation of row size while (len &lt; s.length()){ if (!(isalpha(s.at(len)))){ // Check to see if all characters are alphabetic. exit("Matrix contains invalid characters!"); return false; } len++; } if (max == 0){ //if max is not set. max = len; len = 0; } else if (!(max == len)){ //if they are different, then appropriate //error message is returned. exit("Matrix is not in a correct format!"); return false; } else { //else it resets. len = 0; } } rowSize -= 1; columnSize = s.length(); //the last length is equal to column size return true; } </code></pre>
    singulars
    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.
 

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