OPEN / INPUT?
-
- Veteran
- Posts: 1055
- Joined: Sun Jan 02, 2005 2:11 pm
- Location: At my computer
- Contact:
- Mitth'raw'nuruodo
- Veteran
- Posts: 839
- Joined: Sat Jan 22, 2005 11:04 am
- Location: Eastern Coast of US
- Contact:
Hey Hey, do you know why that that's the limit?
Well do you know the limit of an array in QB?
It's 32767 if I'm not mistaken....
Now do you know that a String is just an array of chars?
Makes sense doesn't it....
In C++ the is a var called char, it's like int, or double, or long, or string, etc.
a char is like a string but only 1 value....
It's very easy to convert chars to ints, because when you cast a char to an int you get the ASCII value of that char in the int.
So
char i='9';
cout<<int(i)<<endl;
would output
57
and
int i=57;
cout<<char(i)<<endl;
would output
9
Notice the ' ', you have to do that for a char like you do " " for a string.
Now C++ can't directly cast a string to an int so what so you do? You make each one a char that you want to....
Now in QB this is easy you have the val() and the str$()
But in c++ its not that easy
but to make a certain part of a string in C++ an int is easy cause you don't need to deal with substr (like mid$ in QB):
Since a String is an array of chars:
string A="12334"
cout<<int(A[1])<<endl;
Guess what that would output?
A[1] is a char so
it would output ascii(2) what ever that is
wait a minute you said A[1] = 2?
isn't A[1] = 1? cause its in the first slot?
NO it starts at 0! then the second pos is 1, very confusing expesially for the .length() method and converting...heh
Oh well I guess I went off topic again...heh
Well do you know the limit of an array in QB?
It's 32767 if I'm not mistaken....
Now do you know that a String is just an array of chars?
Makes sense doesn't it....
In C++ the is a var called char, it's like int, or double, or long, or string, etc.
a char is like a string but only 1 value....
It's very easy to convert chars to ints, because when you cast a char to an int you get the ASCII value of that char in the int.
So
char i='9';
cout<<int(i)<<endl;
would output
57
and
int i=57;
cout<<char(i)<<endl;
would output
9
Notice the ' ', you have to do that for a char like you do " " for a string.
Now C++ can't directly cast a string to an int so what so you do? You make each one a char that you want to....
Now in QB this is easy you have the val() and the str$()
But in c++ its not that easy
but to make a certain part of a string in C++ an int is easy cause you don't need to deal with substr (like mid$ in QB):
Since a String is an array of chars:
string A="12334"
cout<<int(A[1])<<endl;
Guess what that would output?
A[1] is a char so
it would output ascii(2) what ever that is
wait a minute you said A[1] = 2?
isn't A[1] = 1? cause its in the first slot?
NO it starts at 0! then the second pos is 1, very confusing expesially for the .length() method and converting...heh
Oh well I guess I went off topic again...heh
"But...It was so beutifully done"
-
- Veteran
- Posts: 1055
- Joined: Sun Jan 02, 2005 2:11 pm
- Location: At my computer
- Contact:
- Mitth'raw'nuruodo
- Veteran
- Posts: 839
- Joined: Sat Jan 22, 2005 11:04 am
- Location: Eastern Coast of US
- Contact:
What you didn't hear me or somtin? Ok here I go again I said:
Ummm I would have to be the stupidest person in the world if I thought thats what you ment....lol
Lets see simpl:
- char is a var thats a string with 1 value
- string is a var thats an array of chars
- In C++ you can get a char var by getting that element in a string array that corresponds to the position in the string, which starts at zero.
- EXAMPLE:
OUTPUT:
m
Is that good enough now or were you joking? he he.
Was that what you wanted?Mitth'raw'nuruodo wrote:Hey Hey, do you know why that that's the limit?
Well do you know the limit of an array in QB?
It's 32767 if I'm not mistaken....
Now do you know that a String is just an array of chars?
Makes sense doesn't it.... ........................
...........................................................
..........................................................
..............................................................
Ummm I would have to be the stupidest person in the world if I thought thats what you ment....lol
Lets see simpl:
- char is a var thats a string with 1 value
- string is a var thats an array of chars
- In C++ you can get a char var by getting that element in a string array that corresponds to the position in the string, which starts at zero.
- EXAMPLE:
Code: Select all
String Hello = "from";
char A = Hello[3];
//since 3 is the 4th position (starts at 0) in the string the output to A is 'm'.
cout<<A<<endl; //that's PRINT in QB
m
Is that good enough now or were you joking? he he.
"But...It was so beutifully done"
-
- Veteran
- Posts: 1055
- Joined: Sun Jan 02, 2005 2:11 pm
- Location: At my computer
- Contact:
- Mitth'raw'nuruodo
- Veteran
- Posts: 839
- Joined: Sat Jan 22, 2005 11:04 am
- Location: Eastern Coast of US
- Contact:
-
- Veteran
- Posts: 1055
- Joined: Sun Jan 02, 2005 2:11 pm
- Location: At my computer
- Contact: