Note that there are some explanatory texts on larger screens.

plurals
  1. POSome guidance please
    primarykey
    data
    text
    <p>I have this code, which is basically me trying to learn c++, and I can't figure out why I keep getting the two errors</p> <blockquote> <p>error: request for member 'length' in 'cInputChar', which is of non-class type 'char [0]'</p> </blockquote> <p>and</p> <blockquote> <p>error: invalid conversion from 'char*' to 'char'</p> </blockquote> <p>I think it has something to do with the way I am declaring the char variable <code>cInputChar</code>. The problem is definitely associated with the <code>getChar</code> function.</p> <p><strong>My code is below:</strong></p> <pre><code>int getInteger(int&amp; nSeries); char getChar(char&amp; cSeriesDecision, int nSeries); int main() { int nSeries = 0; char cSeriesDecision = {0}; getInteger(nSeries); getChar(cSeriesDecision, nSeries); return 0; } //The function below attempts to get an integer variable without using the '&gt;&gt;' operator. int getInteger(int&amp; nSeries) { //The code below converts the entry from a string to an integer value. string sEntry; stringstream ssEntryStream; while (true) { cout &lt;&lt; "Please enter a valid series number: "; getline(cin, sEntry); stringstream ssEntryStream(sEntry); //This ensures that the input string can be converted to a number, and that the series number is between 1 and 3. if(ssEntryStream &gt;&gt; nSeries &amp;&amp; nSeries &lt; 4 &amp;&amp; nSeries &gt; 0) { break; } cout &lt;&lt; "Invalid series number, please try again." &lt;&lt; endl; } return nSeries; } //This function tries to get a char from the user without using the '&gt;&gt;' operator. char getChar(char&amp; cSeriesDecision, int nSeries) { char cInputChar[0]; while (true) { cout &lt;&lt; "You entered series number " &lt;&lt; nSeries &lt;&lt; "/nIs this correct? y/n: "; cin.getline(cInputChar, 1); if (cInputChar.length() == 1) { cSeriesDecision = cInputChar; break; } cout &lt;&lt; "/nPlease enter a valid decision./n"; } return cSeriesDecision; } </code></pre>
    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.
 

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