'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
'Chapter 32. Character arrays can be used like files
'Example #2 A program that reads from a character string
'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
$CPPHDR
$NOMAIN
'Translate with MinGW Win no Win Includes OR
'Translate with MinGW Win no Win Inc Unicode
'For Unicode uncomment the next line and add -municode to compile line
'$ONEXIT "ULEX.EXE $FILE$.CPP TCHARXLATER.TXT"
'$ONEXIT "TDMGPP.BAT $FILE$ -m64 con"
'$ONEXIT "NUWENGPP.BAT $FILE$ -m64 con"
'Translate with Win no Win Includes OR
'Translate with Win no Win Inc Unicode
'For Unicode uncomment
'$ONEXIT "ULEX.EXE $FILE$.CPP TCHARXLATER_VC.TXT"
$ONEXIT "VSCPP.BAT $FILE$ -m64 con"
'------------------------------------------------------------------------------
'g++ whines about depreciated but this example needs it. it is NOT a default #include
#include <strstream>
'------------------------------------------------------------------------------
Function main () As int
Raw As char a[1024]
Raw As istrstream b(a, 1024)
a$ = "45.656"
Raw As double k, p
b.seekg(0) ' Start from first character.
b >> k
k = k + 1
cout << k << endl
a$ = "444.23 56.89"
b.seekg(0)
b >> k >> p
cout << k << ", " << p + 1 << endl
Pause
Function = EXIT_SUCCESS
End Function
Result:
46.656
444.23, 57.89