Rewriting depriciiated oststream implementations HELP!

I am editing a an old but very useful program from 1999. Please help me properly replace outdated parts of the code. Here I have some headers that are outdated. Replacing them would require me edit the code. Please help me out!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

#include <strstrea.h>
#include <strstream>
#include <fstream.h>
#include <iomanip.h>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <commdlg.h>
#include <stddef.h>
#include <winioctl.h>
#include <winbase.h>


 void failsave(char *filename)
{
	ostrstream outstr(buffer,sizeof(buffer));
	outstr<<"Can't save "<<filename<<". Disk may be full!"<< ends;
	MessageBox(hFrameWnd,buffer,NULL,MB_OK);
}

int failopen(char *filename)
{
	ostrstream outstr(buffer,sizeof(buffer));
	outstr<<"Can't open "<<filename<<ends;
	if( IDCANCEL==MessageBox(hFrameWnd,buffer,NULL,MB_OKCANCEL))
      return 1;
    else return 0;
}
Last edited on
What parts are outdated? I see a few errors regarding undeclared variables and one pet peeve of mine where you're guessing at the reason for a failure instead of using a modicum of effort to figure it out definitively.

Please just delete Line 18. The function "GetLastError()" will return a standardized code (in Windows anyway) that indicates the reason for the most recent failure. Alternatively, the function "GetDiskFreeSpaceEx()" will tell you the amount of free disk space remaining on the target volume. There is no reason to speculate about this stuff.
Thank you!

#include <strstrea.h>
#include <fstream.h>
#include <iomanip.h>

are outdated and not included into VS 2013. Thus ostrstream outstr function is not recognized and gives fatal error. This is what I am trying to replace.
Please help me properly replace outdated parts of the code
1
2
3
4
5
6
7
#include <strstrea.h>
#include <fstream.h>
#include <iomanip.h>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <stddef.h> 

All those headers are outdated.

Get a modern compiler and use the correct headers:
1
2
3
4
5
6
7
#include <strstream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstddef> 



It looks like I've been ninja'd in regards to the answer. One more thing to add though, you're forgetting to indicate the namespace for the "ostrstream" object. The declarations should be: std::ostrstream VARIABLE_NAME ...

Also try to use "MessageBoxA()" or "MessageBoxW()" directly whenever you can instead of having Macros decide for you. This will save you a potential headache when it suddenly decides to switch to the other character version for no reason and starts displaying garbage in the text fields.
Topic archived. No new replies allowed.