Thread: File IO with .Net SDK and platform SDK

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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!!!

  2. #2
    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.

  3. #3
    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!!!

  4. #4
    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