+ 6
Why am getting this error??
#include<iostream> #include<math.h> #include<string> using namespace std; long lineFor(int x){ return (pow(11,x)); } int main(){ int rows; string line; cout<<"Enter the number of rows: "; cin>>rows; for(int y=0;y<=rows;y++){ line=(string)lineFor(y);//Here comes the error for(int s=line.length();s>=0;s--){ cout<<" "; } cout<<line<<endl; } }
2 Answers
+ 6
it says invalid conversion
+ 6
You can't directly convert an integer, long etc,. to a string in C++. Use the below code instead. And don't forget to add #include<sstream>.
long a = lineFor(y);
ostringstream ss;
ss<<a;
line = ss.str();