Converting an integer into a string - Programmers Heaven

#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# Converting an integer into a string

Posts: 4Member
i want to convert an integer to a string in turbo pascal, why will these lines of code cause an error, strings can hold numbers cant they?
or am i looking at it from thew wrong angle

I : integer;
S : String;

I:=S

any help would be appriciated from a clueles begginer

• Posts: 6,349Member
: i want to convert an integer to a string in turbo pascal, why will these lines of code cause an error, strings can hold numbers cant they?
: or am i looking at it from thew wrong angle
:
: I : integer;
: S : String;
:
: I:=S
:
: any help would be appriciated from a clueles begginer
:
Use the Str() function.
• Posts: 52Member
var
i: integer;
s: string;
begin
str(i, s);
write(i);
• Posts: 72Member
you can't store a integer variable into a string var.

note that you can store an integer value in a real var. etc

• Posts: 6,349Member
: you can't store a integer variable into a string var.
:
: note that you can store an integer value in a real var. etc
:
:
You can store an integer in a string, but when you want to perform a calculation with that integer, you need to convert it to an integer. It is possible to store any variable in any other variable, as long as you define the rules to convert the two.
• Posts: 72Member
: : you can't store a integer variable into a string var.
: :
: : note that you can store an integer value in a real var. etc
: :
: :
: You can store an integer in a string, but when you want to perform a calculation with that integer, you need to convert it to an integer. It is possible to store any variable in any other variable, as long as you define the rules to convert the two.
:

i tried, it doesnt work , the compiler will tell you type mismatch.

• Posts: 6,349Member
: : : you can't store a integer variable into a string var.
: : :
: : : note that you can store an integer value in a real var. etc
: : :
: : :
: : You can store an integer in a string, but when you want to perform a calculation with that integer, you need to convert it to an integer. It is possible to store any variable in any other variable, as long as you define the rules to convert the two.
: :
:
: i tried, it doesnt work , the compiler will tell you type mismatch.
:
You need to convert it using Str() or Val(). You cannot directly assign it.