Thread: File IO with .Net SDK and platform SDK

  1. #1
    Registered User AtomRiot's Avatar
    Join Date
    Jan 2003
    Posts
    120

    File IO with .Net SDK and platform SDK

    Ok, i know this is my faul but I have a computer that my compiler is the command line compiler for c++ and everything works fine except the fact that the headers that it gets for some of the stuff is the .Net headers.

    I need to do some simple file IO but I am having problems. My setup is a windows 2000 server with the Platform Core SDK and the .Net 1.1 Framework SDK.

    I have been developing on this for a while now and not had to do any file IO but now the need has risen and I cant seem to do the normal IO that i know.

    I tried to include iostream or fstream and I get an error of file not found. the file is int the sdk\src\crt or sdk\src\win64\crt and i tried pointing directly to that file and i get an error saying it is trying to use c directives.

    all i need to do is write some numbers to a file so is there some easy way to output using the .Net SDK?
    All Your Base Are Still Belong to Someone!!!
    And you Remember that!!!

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    my compiler is the command line compiler for c++...I tried to include iostream or fstream and I get an error of file not found.
    Presumably you are using cl.exe from sdk/.NET? If so, I'd suggest you use the Visual C++ Toolkit 2003 ( see also the sticky at the top of this board). You'll still need the sdk/.NET stuff for windows and its resource compiler (is nmake.exe in the sdk/.NET?) but you'll get the STL.

    If, however, you wish to use windows file io then you might want to take a look at the file management functions.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Registered User AtomRiot's Avatar
    Join Date
    Jan 2003
    Posts
    120
    Ok, i tried the vc toolkit. I am able to include iostream but when i try to create an fstream, i get:

    using:
    Code:
    #include <iostream>
    #include <fstream>
    ...
    ofstream newStream;
    ...
    I get this error.
    Code:
    main.cpp(1142) : error C2065: 'ofstream' : undeclared identifier
    main.cpp(1142) : error C2146: syntax error : missing ';' before identifier 'newS
    tream'
    main.cpp(1142) : error C2065: 'newStream' : undeclared identifier
    but if i take out the fstream newStream; call then it will work just fine.
    I also get the following on compile when i have iostream included.

    Code:
    main.cpp
    C:\Program Files\Microsoft Visual C++ Toolkit 2003\include\ostream(574) : warnin
    g C4530: C++ exception handler used, but unwind semantics are not enabled. Speci
    fy /EHsc
    C:\Program Files\Microsoft Visual C++ Toolkit 2003\include\istream(828) : warnin
    g C4530: C++ exception handler used, but unwind semantics are not enabled. Speci
    fy /EHsc
    C:\Program Files\Microsoft Visual C++ Toolkit 2003\include\istream(1064) : warni
    ng C4530: C++ exception handler used, but unwind semantics are not enabled. Spec
    ify /EHsc
    C:\Program Files\Microsoft Visual C++ Toolkit 2003\include\ostream(479) : warnin
    g C4530: C++ exception handler used, but unwind semantics are not enabled. Speci
    fy /EHsc
            C:\Program Files\Microsoft Visual C++ Toolkit 2003\include\ostream(471)
    : while compiling class-template member function 'std::basic_ostream<_Elem,_Trai
    ts>::_Myt &std::basic_ostream<_Elem,_Traits>::put(_Elem)'
            with
            [
                _Elem=wchar_t,
                _Traits=std::char_traits<wchar_t>
            ]
            C:\Program Files\Microsoft Visual C++ Toolkit 2003\include\ostream(561)
    : see reference to class template instantiation 'std::basic_ostream<_Elem,_Trait
    s>' being compiled
            with
            [
                _Elem=wchar_t,
                _Traits=std::char_traits<wchar_t>
            ]
    C:\Program Files\Microsoft Visual C++ Toolkit 2003\include\ostream(479) : warnin
    g C4530: C++ exception handler used, but unwind semantics are not enabled. Speci
    fy /EHsc
            C:\Program Files\Microsoft Visual C++ Toolkit 2003\include\ostream(471)
    : while compiling class-template member function 'std::basic_ostream<_Elem,_Trai
    ts>::_Myt &std::basic_ostream<_Elem,_Traits>::put(_Elem)'
            with
            [
                _Elem=char,
                _Traits=std::char_traits<char>
            ]
            C:\Program Files\Microsoft Visual C++ Toolkit 2003\include\ostream(922)
    : see reference to class template instantiation 'std::basic_ostream<_Elem,_Trait
    s>' being compiled
            with
            [
                _Elem=char,
                _Traits=std::char_traits<char>
            ]
    C:\Program Files\Microsoft Visual C++ Toolkit 2003\include\istream(99) : warning
     C4530: C++ exception handler used, but unwind semantics are not enabled. Specif
    y /EHsc
            C:\Program Files\Microsoft Visual C++ Toolkit 2003\include\istream(89) :
     while compiling class-template member function 'bool std::basic_istream<_Elem,_
    Traits>::_Ipfx(bool)'
            with
            [
                _Elem=wchar_t,
                _Traits=std::char_traits<wchar_t>
            ]
            C:\Program Files\Microsoft Visual C++ Toolkit 2003\include\istream(816)
    : see reference to class template instantiation 'std::basic_istream<_Elem,_Trait
    s>' being compiled
            with
            [
                _Elem=wchar_t,
                _Traits=std::char_traits<wchar_t>
            ]
    C:\Program Files\Microsoft Visual C++ Toolkit 2003\include\istream(99) : warning
     C4530: C++ exception handler used, but unwind semantics are not enabled. Specif
    y /EHsc
            C:\Program Files\Microsoft Visual C++ Toolkit 2003\include\istream(89) :
     while compiling class-template member function 'bool std::basic_istream<_Elem,_
    Traits>::_Ipfx(bool)'
            with
            [
                _Elem=char,
                _Traits=std::char_traits<char>
            ]
            C:\Program Files\Microsoft Visual C++ Toolkit 2003\include\istream(1054)
     : see reference to class template instantiation 'std::basic_istream<_Elem,_Trai
    ts>' being compiled
            with
            [
                _Elem=char,
                _Traits=std::char_traits<char>
            ]
    C:\Program Files\Microsoft Visual C++ Toolkit 2003\include\xstring(1453) : warni
    ng C4530: C++ exception handler used, but unwind semantics are not enabled. Spec
    ify /EHsc
            C:\Program Files\Microsoft Visual C++ Toolkit 2003\include\xstring(1444)
     : while compiling class-template member function 'void std::basic_string<_Elem,
    _Traits,_Ax>::_Copy(std::basic_string<_Elem,_Traits,_Ax>::size_type,std::basic_s
    tring<_Elem,_Traits,_Ax>::size_type)'
            with
            [
                _Elem=char,
                _Traits=std::char_traits<char>,
                _Ax=std::allocator<char>
            ]
            C:\Program Files\Microsoft Visual C++ Toolkit 2003\include\stdexcept(39)
     : see reference to class template instantiation 'std::basic_string<_Elem,_Trait
    s,_Ax>' being compiled
            with
            [
                _Elem=char,
                _Traits=std::char_traits<char>,
                _Ax=std::allocator<char>
            ]
    Microsoft (R) Incremental Linker Version 7.10.3077
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
    /out:main.exe
    main.obj
    resource.res
    and i always get the part at the top talking about unwind symantics are not enabled.
    Last edited by AtomRiot; 12-14-2004 at 09:32 AM.
    All Your Base Are Still Belong to Someone!!!
    And you Remember that!!!

  4. #4
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    For the first error you possibly need to include the std namespace:
    Code:
    #include <iostream>
    #include <fstream>
    using namespace std;
    For the second error, you need to enable exception support by using /EHsc or /EHa on the command line. This is a batch file I use to compile with the VC toolkit. Save it as a text file with the name vc_compile.bat and drag a .c or .cpp file onto it to compile.
    Code:
    :: Drag a C or C++ file onto this batch file to compile it with Visual C++
    :: Edit this batch file as needed for your environment
    
    :: Call vcvars32.bat for your installation of VC++.
    
    :: This is for VC 6.
    call "C:\Program Files\Microsoft Visual Studio\VC98\Bin\vcvars32"
    :: This is for VC.NET.
    call "C:\Program Files\Microsoft Visual Studio .NET\Vc7\bin\vcvars32"
    :: This is for VC.NET 2003.
    call "C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\bin\vcvars32"
    :: This is for VC Toolkit 2003.
    call "C:\Program Files\Microsoft Visual C++ Toolkit 2003\vcvars32"
    
    :: Set environment variables for Platform SDK:
    SET INCLUDE=%INCLUDE%;C:\Program Files\Microsoft SDK\Include;
    SET LIB=%LIB%;C:\Program Files\Microsoft SDK\Lib;
    
    %0\
    cd %0\..
    cd /d %0\..
    
    cls
    
    cl /EHa /GF /W3 %1 KERNEL32.LIB USER32.LIB
    
    @del *.obj
    @echo.
    @pause
    Last edited by anonytmouse; 12-14-2004 at 10:12 AM.

  5. #5
    Registered User AtomRiot's Avatar
    Join Date
    Jan 2003
    Posts
    120
    Ok, i figured out the unwind semantics thing, i was not using exception handling. I love google.

    I also in using the exception handling in the compiler have eliminated that long list of pseudo errors that i was getting.

    I am still having troubles finding a way to use fstream to write a file. it would not be such a big deal but i am working on a joint project with another person and they have already turned in to my director a version with an ofstream file created. Any input would be great.

    would there be a better way to do file i/o? i have went around this issue by using fprintf but that is not acceptable in this situation.

    I am using the win32 api and was not sure but thought that using an fstream class would be the most effective file output method to stay with the win32 api programming method.
    All Your Base Are Still Belong to Someone!!!
    And you Remember that!!!

  6. #6
    Registered User AtomRiot's Avatar
    Join Date
    Jan 2003
    Posts
    120
    awesome man, thanks. the namespace was all i needed after the exception handling.

    also, thanks for the batch, i had a few that did much in the same as the one you posted.

    i always forget the namespace.
    All Your Base Are Still Belong to Someone!!!
    And you Remember that!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Latest Platform SDK includes MFC 4.2 source code!
    By Codeplug in forum Windows Programming
    Replies: 5
    Last Post: 04-04-2006, 10:49 AM
  2. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  3. Visual C++ 2005 linking and file sizes
    By Rune Hunter in forum C++ Programming
    Replies: 2
    Last Post: 11-12-2005, 10:41 PM
  4. Platform SDK ioCompletionPort examples
    By slimtim in forum Windows Programming
    Replies: 16
    Last Post: 01-15-2005, 01:33 AM
  5. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 07:05 PM