Ok here is the output and the error results: (I can see that there is some
stupid mistake in the VS.NET setting that I have and I am not able to figure
out what it is.
Code:
#include <iostream>
#include <fstream>
#include <cstdlib>
#define MAX 2
void main (){
int VarOne=1, VarTwo=0, VarThree=0, VarFour=0;
ifstream OpenFile("test.DAT", ios::in);
if (!OpenFile) cerr<<"Input File cannot be read \n";
OpenFile.close();
cout << "test" << endl;
return;
}
Errors:
------ Build started: Project: Chain, Configuration: Debug Win32 ------
Compiling...
temp.cpp
c:\temp\Chain\temp.cpp(7) : error C2065: 'ifstream' : undeclared identifier
c:\temp\Chain\temp.cpp(7) : error C2146: syntax error : missing ';' before
identifier 'OpenFile'
c:\temp\Chain\temp.cpp(7) : error C2653: 'ios' : is not a class or namespace
name
c:\temp\Chain\temp.cpp(7) : error C2065: 'in' : undeclared identifier
c:\temp\Chain\temp.cpp(7) : error C3861: 'OpenFile': identifier not found,
even with argument-dependent lookup
c:\temp\Chain\temp.cpp(8) : error C3861: 'OpenFile': identifier not found,
even with argument-dependent lookup
c:\temp\Chain\temp.cpp(8) : error C2065: 'cerr' : undeclared identifier
c:\temp\Chain\temp.cpp(9) : error C2228: left of '.close' must have
class/struct/union type
type is ''unknown-type''
c:\temp\Chain\temp.cpp(9) : error C3861: 'OpenFile': identifier not found,
even with argument-dependent lookup
c:\temp\Chain\temp.cpp(10) : error C2065: 'cout' : undeclared identifier
c:\temp\Chain\temp.cpp(10) : error C2065: 'endl' : undeclared identifier
Chain.cpp
c:\temp\Chain\Chain.cpp(5) : error C2143: syntax error : missing ';' before
'<<'
c:\temp\Chain\Chain.cpp(5) : error C2501: 'cout' : missing storage-class or
type specifiers
c:\temp\Chain\Chain.cpp(6) : error C2143: syntax error : missing ';' before
'<<'
c:\temp\Chain\Chain.cpp(6) : error C2501: 'cout' : missing storage-class or
type specifiers
c:\temp\Chain\Chain.cpp(6) : error C2086: 'int cout' : redefinition
c:\temp\Chain\Chain.cpp(5) : see declaration of 'cout'
c:\temp\Chain\Chain.cpp(8) : error C2143: syntax error : missing ';' before
'<<'
c:\temp\Chain\Chain.cpp(8) : error C2501: 'cout' : missing storage-class or
type specifiers
c:\temp\Chain\Chain.cpp(8) : error C2086: 'int cout' : redefinition
c:\temp\Chain\Chain.cpp(5) : see declaration of 'cout'
c:\temp\Chain\Chain.cpp(9) : error C2146: syntax error : missing ';' before
identifier 'SaveFile'
c:\temp\Chain\Chain.cpp(9) : error C2501: 'ofstream' : missing storage-class
or type specifiers
c:\temp\Chain\Chain.cpp(9) : error C2653: 'ios' : is not a class or
namespace name
c:\temp\Chain\Chain.cpp(9) : error C2065: 'out' : undeclared identifier
c:\temp\Chain\Chain.cpp(9) : error C2501: 'SaveFile' : missing storage-class
or type specifiers
c:\temp\Chain\Chain.cpp(9) : error C2078: too many initializers
c:\temp\Chain\Chain.cpp(10) : error C2146: syntax error : missing ';' before
identifier 'LogFile'
c:\temp\Chain\Chain.cpp(10) : error C2501: 'ofstream' : missing
storage-class or type specifiers
c:\temp\Chain\Chain.cpp(10) : error C2086: 'int ofstream' : redefinition
c:\temp\Chain\Chain.cpp(9) : see declaration of 'ofstream'
c:\temp\Chain\Chain.cpp(10) : error C2653: 'ios' : is not a class or
namespace name
c:\temp\Chain\Chain.cpp(10) : error C3861: 'out': identifier not found, even
with argument-dependent lookup
c:\temp\Chain\Chain.cpp(10) : error C2501: 'LogFile' : missing storage-class
or type specifiers
c:\temp\Chain\Chain.cpp(10) : error C2078: too many initializers
c:\temp\Chain\Chain.cpp(11) : error C2059: syntax error : 'if'
c:\temp\Chain\Chain.cpp(12) : error C2059: syntax error : 'if'
c:\temp\Chain\Chain.cpp(13) : error C2146: syntax error : missing ';' before
identifier 'OpenFile'
c:\temp\Chain\Chain.cpp(13) : error C2501: 'ifstream' : missing
storage-class or type specifiers
c:\temp\Chain\Chain.cpp(13) : error C2653: 'ios' : is not a class or
namespace name
c:\temp\Chain\Chain.cpp(13) : error C2065: 'in' : undeclared identifier
c:\temp\Chain\Chain.cpp(13) : error C2501: 'OpenFile' : missing
storage-class or type specifiers
c:\temp\Chain\Chain.cpp(13) : error C2078: too many initializers
c:\temp\Chain\Chain.cpp(14) : error C2059: syntax error : 'if'
c:\temp\Chain\Chain.cpp(18) : error C2086: 'int hhid' : redefinition
c:\temp\Chain\Chain.cpp(2) : see declaration of 'hhid'
c:\temp\Chain\Chain.cpp(18) : error C2086: 'int pid' : redefinition
c:\temp\Chain\Chain.cpp(2) : see declaration of 'pid'
c:\temp\Chain\Chain.cpp(18) : error C2086: 'int tno' : redefinition
c:\temp\Chain\Chain.cpp(2) : see declaration of 'tno'
c:\temp\Chain\Chain.cpp(18) : error C2086: 'int orig4' : redefinition
c:\temp\Chain\Chain.cpp(2) : see declaration of 'orig4'
c:\temp\Chain\Chain.cpp(18) : error C2086: 'int dest4' : redefinition
c:\temp\Chain\Chain.cpp(2) : see declaration of 'dest4'
c:\temp\Chain\Chain.cpp(19) : error C2374: 'temp' : redefinition; multiple
initialization
c:\temp\Chain\Chain.cpp(3) : see declaration of 'temp'
c:\temp\Chain\Chain.cpp(20) : error C2143: syntax error : missing ';' before
'<<'
c:\temp\Chain\Chain.cpp(20) : error C2501: 'SaveFile' : missing
storage-class or type specifiers
c:\temp\Chain\Chain.cpp(20) : error C2086: 'int SaveFile' : redefinition
c:\temp\Chain\Chain.cpp(9) : see declaration of 'SaveFile'
c:\temp\Chain\Chain.cpp(21) : error C2059: syntax error : 'while'
c:\temp\Chain\Chain.cpp(22) : error C2143: syntax error : missing ';' before
'{'
c:\temp\Chain\Chain.cpp(22) : error C2447: '{' : missing function header
(old-style formal list?)
c:\temp\Chain\Chain.cpp(50) : error C2143: syntax error : missing ';' before
'.'
c:\temp\Chain\Chain.cpp(50) : error C2501: 'OpenFile' : missing
storage-class or type specifiers
c:\temp\Chain\Chain.cpp(50) : error C2086: 'int OpenFile' : redefinition
c:\temp\Chain\Chain.cpp(13) : see declaration of 'OpenFile'
c:\temp\Chain\Chain.cpp(51) : error C2143: syntax error : missing ';' before
'.'
c:\temp\Chain\Chain.cpp(51) : error C2501: 'LogFile' : missing storage-class
or type specifiers
c:\temp\Chain\Chain.cpp(51) : error C2086: 'int LogFile' : redefinition
c:\temp\Chain\Chain.cpp(10) : see declaration of 'LogFile'
c:\temp\Chain\Chain.cpp(52) : error C2143: syntax error : missing ';' before
'.'
c:\temp\Chain\Chain.cpp(52) : error C2501: 'SaveFile' : missing
storage-class or type specifiers
c:\temp\Chain\Chain.cpp(52) : error C2086: 'int SaveFile' : redefinition
c:\temp\Chain\Chain.cpp(9) : see declaration of 'SaveFile'
c:\temp\Chain\Chain.cpp(53) : error C2059: syntax error : 'return'
c:\temp\Chain\Chain.cpp(54) : error C2059: syntax error : '}'
c:\temp\Chain\Chain.cpp(54) : error C2143: syntax error : missing ';' before
'}'
c:\temp\Chain\Chain.cpp(54) : error C2059: syntax error : '}'
Generating Code...
Build log was saved at "file://c:\temp\Chain\Debug\BuildLog.htm"
Chain - 66 error(s), 0 warning(s)
---------------------- Done ----------------------
Build: 0 succeeded, 1 failed, 0 skipped
> 1) Do what Matt said
>
[quoted text clipped - 35 lines]
> >> > void main (){
> >> > cout << "This program ta
Jeff F - 22 Dec 2004 17:39 GMT
> Ok here is the output and the error results: (I can see that there is
> some stupid mistake in the VS.NET setting that I have and I am not
[quoted text clipped - 5 lines]
> #define MAX 2
> void main (){
using namespace std;
Like Ron suggested (granted there was a typo). All std library facilities
are in namespace std.
> int VarOne=1, VarTwo=0, VarThree=0, VarFour=0;
> ifstream OpenFile("test.DAT", ios::in);
[quoted text clipped - 3 lines]
> return;
> }
Jeff Flinn
> 1) Do what Matt said
>
> 2) And add
>
> using namespec std;
That should have been:
using namespace std;
> between the include and before you use any of the types defined in the
> standard streams headers.
[quoted text clipped - 30 lines]
>>>> void main (){
>>>> cout << "This program ta
AA - 22 Dec 2004 17:50 GMT
Thanks for the help. That removed the earlier errors but it gave another
bunch of bugs (sorry guys, I have no idea about these MS LIBs/DLLs)
Code:
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
#define MAX 2
void main (){
int VarOne=1, VarTwo=0, VarThree=0, VarFour=0;
ifstream OpenFile("test.DAT", ios::in);
if (!OpenFile) cerr<<"Input File cannot be read \n";
OpenFile.close();
cout << "test" << endl;
return;
}
------ Build started: Project: Chain, Configuration: Debug Win32 ------
Linking...
LIBCD.lib(stdexcpt.obj) : error LNK2005: "public: __thiscall
exception::exception(class exception const &)" (??0exception@@QAE@ABV0@@Z)
already defined in msvcrt.lib(MSVCR71.dll)
LIBCD.lib(stdexcpt.obj) : error LNK2005: "public: __thiscall
bad_cast::bad_cast(char const *)" (??0bad_cast@@QAE@PBD@Z) already defined in
msvcrt.lib(MSVCR71.dll)
LIBCD.lib(stdexcpt.obj) : error LNK2005: "public: __thiscall
bad_cast::bad_cast(class bad_cast const &)" (??0bad_cast@@QAE@ABV0@@Z)
already defined in msvcrt.lib(MSVCR71.dll)
LIBCD.lib(stdexcpt.obj) : error LNK2005: "public: virtual __thiscall
bad_cast::~bad_cast(void)" (??1bad_cast@@UAE@XZ) already defined in
msvcrt.lib(MSVCR71.dll)
LIBCD.lib(dbgheap.obj) : error LNK2005: _malloc already defined in
msvcrt.lib(MSVCR71.dll)
LIBCD.lib(dbgheap.obj) : error LNK2005: _free already defined in
msvcrt.lib(MSVCR71.dll)
LIBCD.lib(crt0dat.obj) : error LNK2005: _exit already defined in
msvcrt.lib(MSVCR71.dll)
LIBCD.lib(crt0dat.obj) : error LNK2005: __exit already defined in
msvcrt.lib(MSVCR71.dll)
LIBCD.lib(crt0dat.obj) : error LNK2005: __cexit already defined in
msvcrt.lib(MSVCR71.dll)
LIBCD.lib(crt0dat.obj) : error LNK2005: __c_exit already defined in
msvcrt.lib(MSVCR71.dll)
LIBCD.lib(fflush.obj) : error LNK2005: _fflush already defined in
msvcrt.lib(MSVCR71.dll)
LIBCD.lib(hooks.obj) : error LNK2005: "void __cdecl terminate(void)"
(?terminate@@YAXXZ) already defined in msvcrt.lib(MSVCR71.dll)
LIBCD.lib(trnsctrl.obj) : error LNK2005: ___CxxFrameHandler already defined
in msvcrt.lib(MSVCR71.dll)
LIBCD.lib(crt0init.obj) : error LNK2005: ___xc_z already defined in
msvcrt.lib(cinitexe.obj)
LIBCD.lib(crt0init.obj) : error LNK2005: ___xc_a already defined in
msvcrt.lib(cinitexe.obj)
LIBCD.lib(crt0init.obj) : error LNK2005: ___xi_z already defined in
msvcrt.lib(cinitexe.obj)
LIBCD.lib(crt0init.obj) : error LNK2005: ___xi_a already defined in
msvcrt.lib(cinitexe.obj)
LIBCD.lib(winxfltr.obj) : error LNK2005: ___CppXcptFilter already defined in
msvcrt.lib(MSVCR71.dll)
LIBCD.lib(winxfltr.obj) : error LNK2005: __XcptFilter already defined in
msvcrt.lib(MSVCR71.dll)
LIBCD.lib(crt0.obj) : error LNK2005: _mainCRTStartup already defined in
msvcrt.lib(crtexe.obj)
LIBCD.lib(crt0.obj) : error LNK2005: __amsg_exit already defined in
msvcrt.lib(MSVCR71.dll)
LINK : warning LNK4098: defaultlib 'LIBCD' conflicts with use of other libs;
use /NODEFAULTLIB:library
Debug/Chain.exe : fatal error LNK1169: one or more multiply defined symbols
found
Build log was saved at "file://c:\temp\Chain\Debug\BuildLog.htm"
Chain - 22 error(s), 1 warning(s)
---------------------- Done ----------------------
Build: 0 succeeded, 1 failed, 0 skipped
> > 1) Do what Matt said
> >
[quoted text clipped - 40 lines]
> >>>> void main (){
> >>>> cout << "This program ta
Nikola Dudar [MSFT] - 06 Jan 2005 02:33 GMT
I guess you have several projects. One or several of them are compiled with
/MT (linking to multi-threaded CRT library), when another project is linked
to static singlethreaded CRT (/ML). These two runtimes cannot be mixed in
one binary, so you need to go back to properties of your projects and check
that your settings are consistent. You can check this in Project properties
dialog. Open this dialog with right click on the project name in the
Solution Explorer then click on Configuration Properties, then C++ and then
Code Generation.
You may also find this topic helpfull