![]() ![]() ![]() ![]() ![]() ![]() ![]() |
|
When I move my C++ source between the gbar/unix and my pc/windows I have problems with line-shifts.
Unix and windows/DOS represent line-shifts in different ways. To avoid problems you should always keep your files in unix format.
Emacs can use several different coding systems. To save your text-file in unix format, while you are editing the file execute the command
C-x <RET> f CODING <RET>'
where the CODING for instance could be 'raw-text-unix'. The text file will now be in unix format (and the characters to the left in the mode line will change to -(Unix)%% ). The file will be in unix format also when you later open it again in Emacs.
Read about CODING in Emacs menu: Help/Manuals/Browse Manual with Info/Emacs/(Coding Systems|Specify Coding| ...)
My WExpressionShop program sometimes writes curious characters in numbers, something like this
(x + 3.4a¸±a + y) * (x + 3.4a€²a + y)
I have used the proposed method from the available C++ files (for the Val class):
#include <strstream> .........
{ ostrstream os; os<<theVal.NumVal; return string(os.str()); }
What is wrong?
The program does not work on all platforms (sorry). os.str() gives a pointer to a string not necessarily terminated by a null-character. The program above should be changed to
{ ostrstream os; os << theVal.NumVal << '\0'; return string(os.str()); }
A more complicated solution is shown on the slide #3 in the slide set about Symbolic Expression:
{ string res; char* p; ostrstream os; os << theVal.NumVal; p= os.str(); for(int i=0;i<os.pcount();i++){res+= p[i];} return res; }
The double to string conversion could be done in a simpler way by using the library <sstream> and the ostringstream class, but as far as I can see that library has not yet been implemented in the gcc 2.95.2 compiler.
Hans Bruun ( hab@imm.dtu.dk ) 21.06.01