Hi,
this is "elementary my dear watson" stuff, but it beats me.
I use the following:
Code:
cout<<"enter a file name\n\n";
cin>>filenam;
filename = filenam += ".txt";
ifstream codedfile( filename.c_str() );
if ( codedfile.is_open() )
{
codedfile>>sentstring;
to open a file and read it. It's a text file and contains just the string 169abc456fgp
so now
the value of the variable sentstring is 169abc456fgp
- correct?
The following sort of thing:
Code:
int une;
une = sentstring[0];
cout<<"first element in sentstring is: "<<une;
should show that une is 1.
But that's not an integer 1, it's a character from a string, so I can't expect that the following:
Code:
int deux;
deux= une + 9:
will yield a value of 10.
I must first convert une to type int.
However, if I try it:
Code:
int une, deux, trois;
une = sentstring[0];
cout<<"first element in sentstring is: "<<une;
//convert char 1 to int 1
deux=(int) une;
trois=deux + 9;
cout<<"first element in sentstring PLUS 9 = "<<une;
I get 53 or something equally mad.
There must be a simple answer.
In the same vein ...
in the above example, with sentstring being 169abc456fgp
how do I get my code to convert 1 and then 6 and then 9
to integers, but then to realise that the same thing cannot be done with a and b and c, and then to resume converting to integers at 4 and 5 etc etc. ??
Thanks in anticipation