CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2023

    Compiler error when using "#include <iostream>" and/or "#include <fstream>"

    I'm teaching myself C++ using MS Visual Studio Community 2022, so I'm a newbie. I've written some code and I've decided to write the output of the application to text file, so I added these lines to my code:

    include <iostream>
    include <fstream>

    When I build my solution, I get these errors:

    1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.35.32215\include\yvals_core.h(28): STL1003: Unexpected compiler, expected C++ compiler.
    1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.35.32215\include\yvals_core.h(29,1): fatal error C1189: #error: Error in C++ Standard Library usage

    I can't work out how to fix this, any advice appreciated!

    Thank you.

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012

    Re: Compiler error when using "#include <iostream>" and/or "#include <fstream>"

    You haven't provided a full compilable source code. Also include should be #include. This is a minimum test program:

    #include <iostream>
    int main() {
    	std::cout << "Hello world!\n";
    This source file should have an extension of .cpp. When you installed VS, did you install c/c++ as part of the installation. They are not installed by default.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  3. #3
    Join Date
    Mar 2023

    Re: Compiler error when using "#include <iostream>" and/or "#include <fstream>"

    Sorry, my mistake, I did use "#include" rather than just "include".

    @2kaud - you were right, I had my code in a file with a .c extension. I changed it to a .cpp and it works now. I was using sample code from the pcap libraries which used a .c extension. That will also explain why "#include <string>" didn't work.
    I can't believe it was as simple as renaming the file. It highlighted other errors in the code which I sorted ok.

    Maybe learning C++ and pcap coding at the same time was a step too far

    Thanks a lot for your help, really appreciated!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width