ADVERTISEMENT
ADVERTISEMENT

Rust program to convert an integer into a string

Rust | Convert int to string: Given an integer number, we have to convert it into the string.
Submitted by Nidhi, on October 08, 2021

Problem Solution:

In this program, we will convert an integer number into the string using the to_string() function and print the result.

Program/Source Code:

The source code to convert an integer into the string is given below. The given program is compiled and executed successfully.

// Rust program to convert an integer
// into a string

fn main() 
{
    let mut intVar:i32 = 108;
    let mut strVar=intVar.to_string();
    
    println!("String is : {}",strVar);
}

Output:

String is : 108

Explanation:

Here, we created a variable intVar of i32 type. Then we assigned the value of intVar variable into &str variable using to_string() function. After that, we printed the result.

Rust Basic Programs »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.