how do i define a string variable in the tutorial there are only int float and char
how do i define a string variable in the tutorial there are only int float and char
const int STRING_LEN=512;
char String[STRING_LEN];
Be a leader and not a follower.
[owner has put his foot in his mouth]
lol i found it there is a way just by including the file string
#include <string>
Just declare
string good, char* bad!Code:string s;
Claus Hetzer
Compiler: Borland 5.5 (on Windows)
Solaris CC (on Unix)
Known Languages: C++, MATLAB, Perl, Java
how do i check the value of a string?
As long as you are using the string class and not char*, you can use the normal comparison operators (<,>,==,!=,<=,>=). Also, strings have a method compare( string ) that gives a more quantitative comparison:
If you are using char*'s, you can use the strcmp function; it works the same way as the string.compare() function above.Code:string s1 = "a string", s2 = "another string"; int comparison = s1.compare( s2 ); if (comparison == 0) cout << "The two strings are the same\n"; else if (comparison < 0) cout << "s1 is lexicographically less than s2\n"; else cout << "s2 is lexicographically less than s1\n";
Claus Hetzer
Compiler: Borland 5.5 (on Windows)
Solaris CC (on Unix)
Known Languages: C++, MATLAB, Perl, Java