Note that there are some explanatory texts on larger screens.

plurals
  1. PONeed help getting a function that removes a string from an array to work
    text
    copied!<p>I have a function look that looks through a string array and returns a value that then gets called into the Delete function. Which from that value gets deleted.</p> <p>I put up a lot of the code here, just look at the operator+ function implemented to the Delete function. And see their use in the main function.</p> <p>The operator + adds strings into an array, it takes up four spots int the array. The Delete function is supposed match the first word in the first string to Delete it, but it's telling me there is no word found.</p> <pre><code>#include &lt;iostream&gt; #include &lt;string&gt; #include &lt;fstream&gt; using namespace std; class AR { public: AR(); AR(int ); AR(const AR &amp;); ~AR(){delete []con;} bool Full(){return counter==cap;} int Look(const string &amp; ); AR &amp; operator+(const string ); void Delete(const string &amp;); AR &amp; operator=(const AR &amp;); friend ostream &amp; operator&lt;&lt;(ostream &amp;, AR &amp;); friend ifstream &amp; operator&gt;&gt;(ifstream &amp; , AR &amp;); void Double_size(); private: string *con; int counter; int cap; }; #include "ar.h" AR::AR() { counter = 0; //initializing state of class cap = 2; con = new string[cap]; } AR::AR(int no_of_cells) { counter = 0; cap = no_of_cells; con = new string[cap]; } AR::AR(const AR &amp; Original) { counter = Original.counter; cap = Original.cap; con = new string[cap]; for(int i=0; i&lt;counter; i++) { con[i] =Original.con[i]; } } ostream &amp; operator&lt;&lt;(ostream &amp; out, AR &amp; Original) { for(int i=0; i&lt; Original.counter; i++) { out&lt;&lt;"con[" &lt;&lt; i &lt;&lt;"] = "&lt;&lt; Original.con[i]&lt;&lt;endl; } return out; } AR &amp; AR::operator=(const AR &amp;rhs) { if(this != &amp;rhs) { delete []con; counter= rhs.counter; cap = rhs.cap; con= new string[cap]; for(int i=0;i&lt;counter;i++) { con[i]= rhs.con[i]; } } return *this; } ifstream &amp; operator&gt;&gt;(ifstream &amp; in, AR &amp; Original) { Original.counter = 0; while(!in.eof() &amp;&amp; Original.counter&lt;Original.cap) { in&gt;&gt;Original.con[Original.counter]; (Original.counter)++; } return in; } AR &amp; AR::operator+(const string word) { if(Full()) //conditions if array is full or empty { Double_size(); // capacity get's doubled } con[counter]=word; counter++; return *this; } void AR::Double_size() { cap *= 2; string *tmp = new string[cap]; for(int i=0;i&lt;counter;i++) { tmp[i]= con[i]; } delete []con; con = tmp; } int AR::Look(const string &amp; word) { for(int i=0;i&lt;counter;i++) { if( con [i] == word) return i; } return -1; } void AR::Delete(const string &amp; word) { int loc = Look(word); if (loc == -1) { cout&lt;&lt;"word not found\n"; } else { for(int i=0;i&lt;counter-1,i++;) { con[i]= con[i+1]; } } } #include &lt;iostream&gt; #include &lt;string&gt; #include "ar.h" using namespace std; int main() { cout&lt;&lt;"invoking the default constructor"&lt;&lt;endl; AR myAr; cout&lt;&lt;"Output after default constructor called\n"; cout&lt;&lt;myAr&lt;&lt;endl&lt;&lt;endl; cout&lt;&lt;"invoking the explicit-value constructor "&lt;&lt;endl; AR yourAr(5); cout&lt;&lt;"Output after explicit-value constructor called\n"; cout&lt;&lt;yourAr&lt;&lt;endl&lt;&lt;endl; cout&lt;&lt;"invoking the copy constructor "&lt;&lt;endl; AR ourAr = myAr; cout&lt;&lt;"Output after copyconstructor called\n"; cout&lt;&lt;ourAr&lt;&lt;endl&lt;&lt;endl; cout&lt;&lt;"testing overloaded operator= with chaining as a member "&lt;&lt;endl; AR X, Y, Z; X = Y = ourAr; cout&lt;&lt;"Output after operator= called\n"; cout&lt;&lt;X&lt;&lt;endl&lt;&lt;endl; cout&lt;&lt;"testing overloaded operator&lt;&lt; overloaded as a friend with chaining "&lt;&lt;endl; cout&lt;&lt;X&lt;&lt;Y&lt;&lt;Z; cout&lt;&lt;endl&lt;&lt;endl; cout&lt;&lt;"testing overloaded operator+ as a member function with chaining, Double_size " &lt;&lt;" and Full."&lt;&lt;endl; AR theirAr(1); theirAr + "Overload the +" + " operator as a member function " + "with chaining to add a string " + "to an Arrary object."; cout&lt;&lt;theirAr&lt;&lt;endl&lt;&lt;endl; cout&lt;&lt;"testing Delete and Look. &lt;&lt;endl; theirAr.Delete("XXXXXX"); theirAr.Delete("Overload"); cout&lt;&lt;"Output after Delete and Look called\n"; cout&lt;&lt;theirArray&lt;&lt;endl&lt;&lt;endl; return 0; } </code></pre>
 

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