+ 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; } }

22nd Mar 2017, 6:21 AM
Prabhakar Dev
Prabhakar Dev - avatar
2 Answers
+ 6
it says invalid conversion
22nd Mar 2017, 6:30 AM
Prabhakar Dev
Prabhakar Dev - avatar
+ 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();
22nd Mar 2017, 6:37 AM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar