נשלח בתאריך: 29 January 2006 בשעה 20:18 | | IP רשוּם
|
|
|
|
מישהו יכול להגיד לי מה הבעיה בתוכנה
הקומפיילר כותב לי שיש לי שתי טעויות
//function that compares between two strings// #include<iostream> #include<string> using namespace std; int main() { string str1="string"; string str2="string"; cout<<"string str1 is :"<<str1<<endl; cout<<"string str2 is :"<<str2<<endl; cout<<endl; //compare str1 and str2// //the function str.compare() compares between the charecters of two strings// cout<<"1."<<endl; size_t comp=str1.compare(str2); cout<<"string str1 is :"; (comp==0)? cout<<"equal",cout<<"not equal" ,cout<<"to string str2"<<endl; return 0; } //function that prints substring// //str.subsr(pos,n); //returns a copy of the substring consisting of //n characters from str, begining at position //pos(defult value 0); if n is too large or is ommited //characters are copied only until the end of s is readed int main() { string str="We go step by step to the target"; cout<<"str is:"<<str<<endl; int n= str.find("step"); string s= str.substr(n); cout<<"s is :"<<s<<endl; s= str.substr(n,12); cout<<"s is:"<<s<<endl; return 0; } //function that combines two difrent strings to one// int main() { string str="vlad"; cout<<"string str is:"<<str<<endl; string s ; s= str+"world"; cout<<"s is :"<<endl; return 0; } //function that shows the length of string// //the function str.length() return a value of type string::size_type //containing the number of characters in string// int main() { string str= "C++ is best computer language"; cout<<"str is :"<<str<<endl; cout<<"lentgh of string is:"<<str.length()<<endl; return 0; } //function that inserts a character to string// int main() { string str= "C++ language"; string s= "is best"; cout<<"str is :"<<str<<endl; cout<<"s is :"<<s<<endl; //str.insert inserts a copy of s into str at position pos// string::size_type pos=4; str.insert(pos,s); cout<<"str is :"<<str<<endl; return 0; } //function that remowes a character from string// //the function str.append() shows the first character of the string accurance// int main() { string str,s; for (char ch='a';ch<='z';ch++) str.append(1,ch); s=str; cout<<"str is :"<<str<<endl; cout<<"s is :"<<str<<endl; //the function str.append remowes one character pointed by s.begin()// cout<<endl<<"erase one , second character from s"<<endl; s.erase(s.begin(),s.begin()+4); cout<<"s is:"<<s<<endl; return 0; } //Function that compaires between two strings and prints the same // characters of two strings// int main() { string str1="string"; string str2="second string"; cout<<"string str1 is:"<<str1<<endl; cout<<"string str2 is:"<<str2<<endl; //the function str1.compare //(compares between two strings to find a match characters) //and print's the mach// size_t comp=str1.compare(str2); cout<<"string str1 :s"; (comp==0)?cout<<"string":cout<<"second string"; cout<<"to string str2"<<endl; return 0; }
|