Using microsoft visual c++ 2010. Everything is screwing up.
I want to take an input file, write to an output file, and use the lines of the input file as strings.
But...
On previous run, I didn't have that last printf line. So everytime I run it, it just prints 'hello'.
The program isn't finished yet, I'll finish once I get help.
At this point, I am willing enough to get a new compiler.
code:

// new__.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdio.h>
#include "simpio.h"
#include "genlib.h"
#include "Windows.h"
#include <fstream.h>
#include <fstream>
#include <apstring.h>
#pragma warning(disable: 4996)
#pragma warning(disable: 4068)
#pragma warning(disable: 4018)
#pragma warning(disable: 4081)
#pragma error(disable: 4430)

void main()
{
	printf("hello");
	ifstream infile;
	ofstream outfile;
	infile.open("input.txt");
	outfile.open("output.txt");
	apstring string;
	printf("done");
}

!@#$%^& errors:

1>------ Build started: Project: new__, Configuration: Debug Win32 ------
1>  new__.cpp
1>c:\program files\microsoft visual studio 10.0\vc\include\simpio.h(44): warning C4996: 'strncpy': This function or variable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>          c:\program files\microsoft visual studio 10.0\vc\include\string.h(188) : see declaration of 'strncpy'
1>c:\program files\microsoft visual studio 10.0\vc\include\simpio.h(57): warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>          c:\program files\microsoft visual studio 10.0\vc\include\string.h(105) : see declaration of 'strcpy'
1>c:\program files\microsoft visual studio 10.0\vc\include\simpio.h(98): warning C4996: 'sscanf': This function or variable may be unsafe. Consider using sscanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>          c:\program files\microsoft visual studio 10.0\vc\include\stdio.h(325) : see declaration of 'sscanf'
1>c:\program files\microsoft visual studio 10.0\vc\include\simpio.h(135): warning C4996: 'sscanf': This function or variable may be unsafe. Consider using sscanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>          c:\program files\microsoft visual studio 10.0\vc\include\stdio.h(325) : see declaration of 'sscanf'
1>c:\program files\microsoft visual studio 10.0\vc\include\simpio.h(172): warning C4996: 'sscanf': This function or variable may be unsafe. Consider using sscanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>          c:\program files\microsoft visual studio 10.0\vc\include\stdio.h(325) : see declaration of 'sscanf'
1>c:\program files\microsoft visual studio 10.0\vc\include\yvals.h(536): error C2632: 'bool' followed by 'bool' is illegal
1>c:\program files\microsoft visual studio 10.0\vc\include\yvals.h(536): warning C4091: 'typedef ' : ignored on left of 'bool' when no variable is declared
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(21): warning C4068: unknown pragma
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(22): warning C4068: unknown pragma
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(24): warning C4068: unknown pragma
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(25): error C2146: syntax error : missing ';' before identifier 'ios'
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(25): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(25): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(26): warning C4081: expected 'identifier'; found 'else'
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(27): error C2146: syntax error : missing ';' before identifier 'ios_base'
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(27): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(27): error C2378: 'ios' : redefinition; symbol cannot be overloaded with a typedef
1>          c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(25) : see declaration of 'ios'
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(27): warning C4091: '' : ignored on left of 'int' when no variable is declared
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(28): warning C4068: unknown pragma
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(30): warning C4068: unknown pragma
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(31): warning C4068: unknown pragma
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(33): warning C4068: unknown pragma
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(34): error C2146: syntax error : missing ';' before identifier 'ostringstream'
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(34): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(34): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(35): error C2146: syntax error : missing ';' before identifier 'istringstream'
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(35): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(35): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(37): warning C4081: expected 'identifier'; found 'else'
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(38): error C2146: syntax error : missing ';' before identifier 'ostrstream'
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(38): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(38): error C2378: 'ostringstream' : redefinition; symbol cannot be overloaded with a typedef
1>          c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(34) : see declaration of 'ostringstream'
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(38): warning C4091: '' : ignored on left of 'int' when no variable is declared
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(39): error C2146: syntax error : missing ';' before identifier 'istrstream'
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(39): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(39): error C2378: 'istringstream' : redefinition; symbol cannot be overloaded with a typedef
1>          c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(35) : see declaration of 'istringstream'
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(39): warning C4091: '' : ignored on left of 'int' when no variable is declared
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(40): error C2146: syntax error : missing ';' before identifier 'strstream'
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(40): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(40): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(41): warning C4068: unknown pragma
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(43): warning C4068: unknown pragma
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(45): warning C4068: unknown pragma
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(52): warning C4081: expected 'identifier'; found 'if'
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(55): warning C4068: unknown pragma
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(64): error C2371: 'std::streampos' : redefinition; different basic types
1>          c:\program files\microsoft visual studio 10.0\vc\include\iosfwd(128) : see declaration of 'std::streampos'
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(71): error C2371: 'ios' : redefinition; different basic types
1>          c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(27) : see declaration of 'ios'
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(183): warning C4018: '>' : signed/unsigned mismatch
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(197): warning C4018: '>' : signed/unsigned mismatch
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(210): warning C4018: '>' : signed/unsigned mismatch
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(223): warning C4018: '>' : signed/unsigned mismatch
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(236): warning C4018: '>' : signed/unsigned mismatch
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(268): error C2365: 'istream::tie' : redefinition; previous definition was 'data member'
1>          c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(262) : see declaration of 'istream::tie'
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(304): error C2063: 'istream::tie' : not a function
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(416): error C2371: 'std::fstream' : redefinition; different basic types
1>          c:\program files\microsoft visual studio 10.0\vc\include\iosfwd(649) : see declaration of 'std::fstream'
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(418): error C2371: 'std::ofstream' : redefinition; different basic types
1>          c:\program files\microsoft visual studio 10.0\vc\include\iosfwd(648) : see declaration of 'std::ofstream'
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(424): error C2371: 'std::ifstream' : redefinition; different basic types
1>          c:\program files\microsoft visual studio 10.0\vc\include\iosfwd(647) : see declaration of 'std::ifstream'
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(449): warning C4068: unknown pragma
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(453): error C3861: 'G__charformatter': identifier not found
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(462): error C2365: 'endl' : redefinition; previous definition was 'function'
1>          c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(438) : see declaration of 'endl'
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(463): error C2365: 'ends' : redefinition; previous definition was 'function'
1>          c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(439) : see declaration of 'ends'
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(464): error C2365: 'flush' : redefinition; previous definition was 'function'
1>          c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(437) : see declaration of 'flush'
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(465): error C2365: 'ws' : redefinition; previous definition was 'function'
1>          c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(440) : see declaration of 'ws'
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(466): error C2365: 'WS' : redefinition; previous definition was 'function'
1>          c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(444) : see declaration of 'WS'
1>c:\program files\microsoft visual studio 10.0\vc\include\iostream.h(475): fatal error C1083: Cannot open include file: '_iostream': No such file or directory
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Notice that not one of these are actually in MY program.
Please help by telling me what I'm doing wrong and/or suggesting a new compiler and a link to where I can download it for free.
Thanks

First void main() is not standard. Main should always return an int. Secondly if you want to use things from the standard library then you will either need to use a using directive or fully qualify the names.

#include <string>

int main()
{
    string word;  // error compiler does not know what string is
}
#include <string>

using std::string

int main()
{
    string word;  // okay, compiler knows where string is
}
#include <string>

using namespace std;

int main()
{
    string word;  // okay, compiler knows where string is
}

The third snippet of code is not as preferred as the second snippet because including the entire std namespace is not necessary and can cause name conflicts. My rule of thumb is never include anything you don't need.

Another issue with your code is that you are including a bunch of headers but you are not using most of them. I did not see the <string> header in your project.

Lastly why are you using printf() ? If your are programing in c++ use cout and cin. That should get you going.

It sounds like you might be using the Unicode character set and need to change to MultiByte (which will give you less problems with mixed-mode compilation).

With Visual Studio, you can create a console app, a CLR app, an MFC app or mix and match.


Are you still having problems with this?

About half of these are warnings rather than errors (mostly ones relating to standard functions Microsoft considers 'deprecated', which in this case means, "Don't use the standard version, use this spiffy safer new version that happens to lock you into our compiler"). The main reason they appear at all is because you are using the older versions of the header files (e.g., <stdio.h> and <fstream.h> rather than <cstdio> and <fstream> ), which are deprecated (and not just by MS this time). While the newer headers do, in fact, contain the standard functions in question, they are 'grandfathered in', whereas the versions from the any other headers (even the old 'standard' headers) are not.

Anyway, most of these errors will go away once you fix <fstream> . The rest are mostly tied to the (unequivocally non-standard) "simpio.h" , which, given that you are also include <stdio.h> (which, as I said, should be <cstdio> now), is probably completely unnecessary (and did I mention non-standard?).

Oh, if you're serious about getting another compiler, I would look into Code::Blocks, a fairly good IDE which comes with the MinGW port of GCC. The bad news is the debugger, which is awful; but then again, the only really good debugger for C++ under Windows is, in fact, the one that comes with Visual C++. Sorry about that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.