Find any errors in the following and explain how to correct them:

a) ```
std::cout << s.data() << std::endl; // s is "hello"
```
b) ```
erase( s.rfind( "x" ), 1 ); // s is "xenon"
```
c) ```
string& foo()
{
string s( "Hello" );
... // other statements
return;
} // end function foo
```


a) The array returned by data is not null terminated.
b) Function erase is a string class member function (i.e., erase must be called by an object of type string).
c) A value is not being returned from the function (i.e., the return statement should be return s;). The return type should be string not string&—reference returns are dangerous.

Computer Science & Information Technology

You might also like to view...

Identify the compiler errors and state what is wrong with the code.

``` #include << using namespace std; class Dolphin { private: float size; string name; public: Dolphin(){name = “Tosser”; } void SetSize(float s) { size = s;} bool operator > (); }; void Dolphin::operator > () should be operator(Dolphin X) { if(X.size > size) return false; else return true; } int main() { Dolphin Big, Little; Big.SetSize(20); Small.SetSize(15); if(Big > Little) cout << “bigger”; else cout << “smaller”. } ```

Computer Science & Information Technology

To see and switch between open apps, on the taskbar click the ________ button

A) Task View B) Current View C) Live View D) Start Menu

Computer Science & Information Technology

How could you share a newsletter with all the members of your business fraternitywithoutprinting?

What will be an ideal response?

Computer Science & Information Technology

A Boolean variable is initialized to the valueTrueif no initial value is stated when the variable is declared.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology