answersLogoWhite

0


Best Answer

You can perform arithmetic with it.

int x {42};

x *= 2; // ok

std::string s {"Hello"};

s *= 2; // error: std::string::operator*= (int) is undefined

User Avatar

Wiki User

6y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What can you do to an int that you cannot do to a string in C plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is the program to create a string class which stores a string value in c plus plus?

C++ already provides a string class in the C++ standard template library. #include<iostream> #include<string> int main() { using namespace std; string s {"Hello world!"}; cout << s << endl; }


C plus plus code to find the length of a string without using function?

int i = 0; while(str[i] != NULL){ i++; }


Program that input ten names from user c plus plus?

#include<iostream> #include<vector> #include<string> int main() { std::vector<std::string> names; for (int loop=0; loop!=10;) { std::cout << ++loop << " enter a name: "; std::string name; std::cin >> name; names.push_back (name); } }


Write a c plus plus program to use plus operator to display the sum of 2 numbers and concatenation of two strings by using operator overloading?

There is no need to overload the plus operator to achieve this. It is already overloaded with this functionality. #include<iostream> #include<string> int main() { int x=40; int y=2; int z=x+y; std::cout<<x<<" + "<<y<<" = "<<z<<std::endl; std::string s1="Hello "; std::string s2="world!"; std::string s3=s1+s2; std::cout<<"""<<s1.c_str()<<"" + ""<<s2.c_str()<<"" = ""<<s3.c_str()<<"""<<std::endl; return(0); }


How do you write a c plus plus program to print aaaa aaab aabb abbb bbbb?

#include<iostream> #include<string> #include<algorithm> bool compare_no_case (const char a, const char b) { return tolower(a) < towlower (b); } int main() { std::string s {"This is the string to be sorted!"}; std::cout << "Unsorted:\t"" << s << ""\n"; std::sort (s.begin(), s.end(), compare_no_case); std::cout << "Sorted\t:"" << s << ""\n"; }

Related questions

What is the program to create a string class which stores a string value in c plus plus?

C++ already provides a string class in the C++ standard template library. #include<iostream> #include<string> int main() { using namespace std; string s {"Hello world!"}; cout << s << endl; }


C plus plus code to find the length of a string without using function?

int i = 0; while(str[i] != NULL){ i++; }


Int a is literal in C language or not?

int a; -- variable definition"int a" -- string literal


How do you work with string in c plus plus?

The easiest way is to use a std::string object. #include<iostream> #include<string> int main() { std::string s("hello world"); std::cout<<s<<std::endl; } You can also use C-style character arrays if you don't need the full functionality of a std::string object.


Program that input ten names from user c plus plus?

#include<iostream> #include<vector> #include<string> int main() { std::vector<std::string> names; for (int loop=0; loop!=10;) { std::cout << ++loop << " enter a name: "; std::string name; std::cin >> name; names.push_back (name); } }


C plus plus program using function min that take three parameters of type int and returns the minimum of the three?

int min (int a, int b, int c) {if (a


Which Program that will run in C but not in C plus plus?

void main() { int *x = malloc(sizeof(int) * 10); }


Write a c plus plus program to read a line from keyboard?

#include <iostream> #include <string> int main() { std::string myStr = ""; std::cout << std::endl << "Enter a string: "; std::cin >> myStr; system("PAUSE"); return 0; }


Write a c plus plus program to find largest among three number using control statement and ternary operators?

int max (int a, int b) { return a<b?b:a; } int max3 (int a, int b, int c) { return max (max (a, b), c); }


Can you give an example of a structure in C plus plus?

struct point { int x; int y; };


Write a c plus plus program to use plus operator to display the sum of 2 numbers and concatenation of two strings by using operator overloading?

There is no need to overload the plus operator to achieve this. It is already overloaded with this functionality. #include<iostream> #include<string> int main() { int x=40; int y=2; int z=x+y; std::cout<<x<<" + "<<y<<" = "<<z<<std::endl; std::string s1="Hello "; std::string s2="world!"; std::string s3=s1+s2; std::cout<<"""<<s1.c_str()<<"" + ""<<s2.c_str()<<"" = ""<<s3.c_str()<<"""<<std::endl; return(0); }


How to Program for reversal of string ven123kat in c?

#include #include #include int reverse(int i);char st[]="ven123kat";void main() {printf("\nThe string is: %s", st);reverse(0);printf("\nReversed string is: %s", st);getch();}int reverse(int i) {if (i