Ok, I recently have been given an assignment in my CS120 class. I wont go into the details, but our instructor gave of this bit of code to help us.
string fname("aaa");
if(fname.equals("aaa"))
...
Yeah, I have played around with this peice of code of a while now, and I cant seem to yet that command to work. I am one of the few students in my class that has taken C++ before, so I am not totally new to this stuff. I understand that .equals has to be apart of the class string. I was wondering if anyone knew about this, or any syntax errors I might be having. I think out instructor wants us to use fname.equals("aaa") in out program.
I gave up after playing with it for a while and got it to work another way. Heres my code, that does compile. Any input on this topic would be greatly helpful.
Code:
//Project 4, test
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
string fname("aaa");
cout<<fname<<'\n';
if(fname == ("aaa"))
cout<<"Works\n";
else
cout<<"Doesnt work\n";
system("PAUSE");
return 0;
}
Output:
aaa
Works
Press any key to continue . . .
Again, thanks for any help.
-Ep




Reply With Quote