If I created string function can i put int parameters in it ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

If I created string function can i put int parameters in it ?

Functions

19th Jul 2019, 9:04 PM
The unknown 321
The unknown 321 - avatar
8 Answers
+ 1
Yes u can. If in java u can use "Integer.parseInt" but u still need Enter the integer on it. If not it will return to NumberFormatException
19th Jul 2019, 11:01 PM
Dwi Novianto Nugroho
Dwi Novianto Nugroho - avatar
+ 1
yes, i think it will work, because u return string parameters on "return "My number is:"<<var<<endl;" and integer just parentheses.
20th Jul 2019, 3:17 AM
Dwi Novianto Nugroho
Dwi Novianto Nugroho - avatar
+ 1
or try this #include <string> std::string s = std::to_string(42); source: https://stackoverflow.com/questions/5590381/easiest-way-to-convert-int-to-string-in-c
20th Jul 2019, 3:21 AM
Dwi Novianto Nugroho
Dwi Novianto Nugroho - avatar
0
Dwi Noviantp Nugroho In c++ ?
20th Jul 2019, 2:58 AM
The unknown 321
The unknown 321 - avatar
0
Ace #include <iostream> using namespace std; string function(int var){ return "My number is:"<<var<<endl; } int main(){ cout <<function(5); return 0; } I put int var inside the parameters of the string function and I wrote it's value down. Will this work ?
20th Jul 2019, 3:02 AM
The unknown 321
The unknown 321 - avatar
0
What do you mean by parentheses ?
20th Jul 2019, 3:26 AM
The unknown 321
The unknown 321 - avatar
0
What std::to_string does ?
20th Jul 2019, 3:45 AM
The unknown 321
The unknown 321 - avatar
0
Does std::+ to_string converts int to string ?
20th Jul 2019, 3:53 AM
The unknown 321
The unknown 321 - avatar