Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C++ Libraries / January 2005

Tip: Looking for answers? Try searching our database.

Unable to include header files

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
AA - 21 Dec 2004 19:13 GMT
Hi,

I am trying to include the iostream and the fstream classes but VS.NET is
behaving weirdly...This same code was working very well 3 months ago and now
it is not...
Can anybody help me in making the cout as a KNOWN IDENTIFIER?
#include <iostream.h>
#include <fstream.h>
#include <cstdlib>
#define MAX 2
void main (){
cout << "This program ta
Matt Osborn - 21 Dec 2004 21:09 GMT
Old style streams were removed from .NET. Try <iostream> and <fstream>.

> Hi,
>
[quoted text clipped - 9 lines]
> void main (){
> cout << "This program ta
AA - 21 Dec 2004 21:37 GMT
Hi,

I have tried everything. I have the same version of Studio.NET. I think
there is some problem in getting or reading the header files. (don't know
why). it gives errors that the cout, cin, ifstream are all unknown
identifiers....Can you help me in linking the headers...i copied the header
from the installed directory itself to the project but even this did not
worked...

> Old style streams were removed from .NET. Try <iostream> and <fstream>.
>
[quoted text clipped - 11 lines]
> > void main (){
> > cout << "This program ta
Ronald Laeremans [MSFT] - 21 Dec 2004 23:30 GMT
1) Do what Matt said

2) And add

using namespec std;

between the include and before you use any of the types defined in the
standard streams headers.

Ronald Laeremans
Visual C++ team

> Hi,
>
[quoted text clipped - 23 lines]
>> > void main (){
>> > cout << "This program ta
AA - 22 Dec 2004 14: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 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
Jeff F - 22 Dec 2004 17:37 GMT
> 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

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.