Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Unhandled Exception when outputting strings [modified]

Unhandled Exception when outputting strings [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpdebuggingquestion
7 Posts 5 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    capricious_001
    wrote on last edited by
    #1

    Hey Guys, I'm using VC++ 6.0 and I'm having a very stupid problem. I get an unhandled exception error when try to output a string to console. Even the simplest program such as the one below: main.cpp

    #include "stdafx.h"
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    
    void main(void )
    {
    
    	string s = "test=2321";
    
    	cout << s;
    
    }
    

    Will produce an error. I built the same program in Metrowerks Codewarrior, and the program runs fine. No problems whatsoever. For some reason I have problems with it in VC++. This is what i have in my other include file: stdfx.h

    // stdafx.h : include file for standard system include files,
    //  or project specific include files that are used frequently, but
    //      are changed infrequently
    //
    
    #if !defined(AFX_STDAFX_H__A9693917_A7C9_4A6A_B3E1_58638AE54078__INCLUDED_)
    #define AFX_STDAFX_H__A9693917_A7C9_4A6A_B3E1_58638AE54078__INCLUDED_
    
    #if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000
    
    #define WIN32_LEAN_AND_MEAN		// Exclude rarely-used stuff from Windows headers
    
    //#include <stdio.h>
    #include <iostream>
    #include <string>
    
    // TODO: reference additional headers your program requires here
    
    //{{AFX_INSERT_LOCATION}}
    // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
    
    #endif // !defined(AFX_STDAFX_H__A9693917_A7C9_4A6A_B3E1_58638AE54078__INCLUDED_)
    

    I will also list my project options:

    kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /incremental:yes /pdb:"Debug/testing_project2.pdb" /debug /machine:I386 /out:"Debug/testing_project2.exe" /pdbtype:sept 
    

    Does anyone know the reason why this is occuring? I would appreciate any light on the issue. Thanks, Robbie -- modified at 18:50 Saturday 24th June, 2006

    M J S S 4 Replies Last reply
    0
    • C capricious_001

      Hey Guys, I'm using VC++ 6.0 and I'm having a very stupid problem. I get an unhandled exception error when try to output a string to console. Even the simplest program such as the one below: main.cpp

      #include "stdafx.h"
      #include <iostream>
      #include <string>
      
      using namespace std;
      
      
      void main(void )
      {
      
      	string s = "test=2321";
      
      	cout << s;
      
      }
      

      Will produce an error. I built the same program in Metrowerks Codewarrior, and the program runs fine. No problems whatsoever. For some reason I have problems with it in VC++. This is what i have in my other include file: stdfx.h

      // stdafx.h : include file for standard system include files,
      //  or project specific include files that are used frequently, but
      //      are changed infrequently
      //
      
      #if !defined(AFX_STDAFX_H__A9693917_A7C9_4A6A_B3E1_58638AE54078__INCLUDED_)
      #define AFX_STDAFX_H__A9693917_A7C9_4A6A_B3E1_58638AE54078__INCLUDED_
      
      #if _MSC_VER > 1000
      #pragma once
      #endif // _MSC_VER > 1000
      
      #define WIN32_LEAN_AND_MEAN		// Exclude rarely-used stuff from Windows headers
      
      //#include <stdio.h>
      #include <iostream>
      #include <string>
      
      // TODO: reference additional headers your program requires here
      
      //{{AFX_INSERT_LOCATION}}
      // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
      
      #endif // !defined(AFX_STDAFX_H__A9693917_A7C9_4A6A_B3E1_58638AE54078__INCLUDED_)
      

      I will also list my project options:

      kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /incremental:yes /pdb:"Debug/testing_project2.pdb" /debug /machine:I386 /out:"Debug/testing_project2.exe" /pdbtype:sept 
      

      Does anyone know the reason why this is occuring? I would appreciate any light on the issue. Thanks, Robbie -- modified at 18:50 Saturday 24th June, 2006

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      Do you have SP6 installed? I recall getting some very strange compiler/runtime errors on previous SPs. Mostly with _bstr_t, but I wouldn't be shocked if errors happened in other parts of the runtime libraries.

      --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ VB > soccer

      C 1 Reply Last reply
      0
      • M Michael Dunn

        Do you have SP6 installed? I recall getting some very strange compiler/runtime errors on previous SPs. Mostly with _bstr_t, but I wouldn't be shocked if errors happened in other parts of the runtime libraries.

        --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ VB > soccer

        C Offline
        C Offline
        capricious_001
        wrote on last edited by
        #3

        Hey Mike, I applied the update and also removed any intermidiate files as well as the precompiled header files, but still I am getting the same error. Do you think it could be an issue with the project options? Robbie

        1 Reply Last reply
        0
        • C capricious_001

          Hey Guys, I'm using VC++ 6.0 and I'm having a very stupid problem. I get an unhandled exception error when try to output a string to console. Even the simplest program such as the one below: main.cpp

          #include "stdafx.h"
          #include <iostream>
          #include <string>
          
          using namespace std;
          
          
          void main(void )
          {
          
          	string s = "test=2321";
          
          	cout << s;
          
          }
          

          Will produce an error. I built the same program in Metrowerks Codewarrior, and the program runs fine. No problems whatsoever. For some reason I have problems with it in VC++. This is what i have in my other include file: stdfx.h

          // stdafx.h : include file for standard system include files,
          //  or project specific include files that are used frequently, but
          //      are changed infrequently
          //
          
          #if !defined(AFX_STDAFX_H__A9693917_A7C9_4A6A_B3E1_58638AE54078__INCLUDED_)
          #define AFX_STDAFX_H__A9693917_A7C9_4A6A_B3E1_58638AE54078__INCLUDED_
          
          #if _MSC_VER > 1000
          #pragma once
          #endif // _MSC_VER > 1000
          
          #define WIN32_LEAN_AND_MEAN		// Exclude rarely-used stuff from Windows headers
          
          //#include <stdio.h>
          #include <iostream>
          #include <string>
          
          // TODO: reference additional headers your program requires here
          
          //{{AFX_INSERT_LOCATION}}
          // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
          
          #endif // !defined(AFX_STDAFX_H__A9693917_A7C9_4A6A_B3E1_58638AE54078__INCLUDED_)
          

          I will also list my project options:

          kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /incremental:yes /pdb:"Debug/testing_project2.pdb" /debug /machine:I386 /out:"Debug/testing_project2.exe" /pdbtype:sept 
          

          Does anyone know the reason why this is occuring? I would appreciate any light on the issue. Thanks, Robbie -- modified at 18:50 Saturday 24th June, 2006

          J Offline
          J Offline
          Jun Du
          wrote on last edited by
          #4

          I don't have a fix, just some clue. It has something to do with incompatible STL libraries. I encountered similar problem on a UNIX platform long time ago. We couldn't fix it cleanly because we were not allowed to alter the platform setup. But we were able to get rid of it by using old STL implementation. Try to use old STL headers like string.h and iostream.h and see how it goes. Best, Jun

          1 Reply Last reply
          0
          • C capricious_001

            Hey Guys, I'm using VC++ 6.0 and I'm having a very stupid problem. I get an unhandled exception error when try to output a string to console. Even the simplest program such as the one below: main.cpp

            #include "stdafx.h"
            #include <iostream>
            #include <string>
            
            using namespace std;
            
            
            void main(void )
            {
            
            	string s = "test=2321";
            
            	cout << s;
            
            }
            

            Will produce an error. I built the same program in Metrowerks Codewarrior, and the program runs fine. No problems whatsoever. For some reason I have problems with it in VC++. This is what i have in my other include file: stdfx.h

            // stdafx.h : include file for standard system include files,
            //  or project specific include files that are used frequently, but
            //      are changed infrequently
            //
            
            #if !defined(AFX_STDAFX_H__A9693917_A7C9_4A6A_B3E1_58638AE54078__INCLUDED_)
            #define AFX_STDAFX_H__A9693917_A7C9_4A6A_B3E1_58638AE54078__INCLUDED_
            
            #if _MSC_VER > 1000
            #pragma once
            #endif // _MSC_VER > 1000
            
            #define WIN32_LEAN_AND_MEAN		// Exclude rarely-used stuff from Windows headers
            
            //#include <stdio.h>
            #include <iostream>
            #include <string>
            
            // TODO: reference additional headers your program requires here
            
            //{{AFX_INSERT_LOCATION}}
            // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
            
            #endif // !defined(AFX_STDAFX_H__A9693917_A7C9_4A6A_B3E1_58638AE54078__INCLUDED_)
            

            I will also list my project options:

            kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /incremental:yes /pdb:"Debug/testing_project2.pdb" /debug /machine:I386 /out:"Debug/testing_project2.exe" /pdbtype:sept 
            

            Does anyone know the reason why this is occuring? I would appreciate any light on the issue. Thanks, Robbie -- modified at 18:50 Saturday 24th June, 2006

            S Offline
            S Offline
            Sam Hobbs
            wrote on last edited by
            #5

            I used the following code in a simple VC 6 console project I use for testing purposes. I turned off precompiled headers, so the project should be unaffected by anything significant. The program works for me as it should, so you probably have something messed up by your setup. #include #include using namespace std; void main(void ){ string s = "test=2321"; cout << s; } -- modified at 21:36 Saturday 24th June, 2006

            1 Reply Last reply
            0
            • C capricious_001

              Hey Guys, I'm using VC++ 6.0 and I'm having a very stupid problem. I get an unhandled exception error when try to output a string to console. Even the simplest program such as the one below: main.cpp

              #include "stdafx.h"
              #include <iostream>
              #include <string>
              
              using namespace std;
              
              
              void main(void )
              {
              
              	string s = "test=2321";
              
              	cout << s;
              
              }
              

              Will produce an error. I built the same program in Metrowerks Codewarrior, and the program runs fine. No problems whatsoever. For some reason I have problems with it in VC++. This is what i have in my other include file: stdfx.h

              // stdafx.h : include file for standard system include files,
              //  or project specific include files that are used frequently, but
              //      are changed infrequently
              //
              
              #if !defined(AFX_STDAFX_H__A9693917_A7C9_4A6A_B3E1_58638AE54078__INCLUDED_)
              #define AFX_STDAFX_H__A9693917_A7C9_4A6A_B3E1_58638AE54078__INCLUDED_
              
              #if _MSC_VER > 1000
              #pragma once
              #endif // _MSC_VER > 1000
              
              #define WIN32_LEAN_AND_MEAN		// Exclude rarely-used stuff from Windows headers
              
              //#include <stdio.h>
              #include <iostream>
              #include <string>
              
              // TODO: reference additional headers your program requires here
              
              //{{AFX_INSERT_LOCATION}}
              // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
              
              #endif // !defined(AFX_STDAFX_H__A9693917_A7C9_4A6A_B3E1_58638AE54078__INCLUDED_)
              

              I will also list my project options:

              kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /incremental:yes /pdb:"Debug/testing_project2.pdb" /debug /machine:I386 /out:"Debug/testing_project2.exe" /pdbtype:sept 
              

              Does anyone know the reason why this is occuring? I would appreciate any light on the issue. Thanks, Robbie -- modified at 18:50 Saturday 24th June, 2006

              S Offline
              S Offline
              Stephen Hewitt
              wrote on last edited by
              #6

              I use code like this all the time and have no problems. What is the exeption? Can you attach a call stack when the exception is thrown? Steve

              C 1 Reply Last reply
              0
              • S Stephen Hewitt

                I use code like this all the time and have no problems. What is the exeption? Can you attach a call stack when the exception is thrown? Steve

                C Offline
                C Offline
                capricious_001
                wrote on last edited by
                #7

                Hey guys, Thanks for the input. I have a few question though: 1) How would I turn off the pre-compiled headers? Is it just as good as cleaning out the the intermediate and precompiled headers before a build or do I still need to turn them off? 2) I tried including iostream.h and string.h however that doesnt seem to work either. I still receive the same error. 3) As for the unhandled exception, its an access violation with error code: 0xC0000005, but I'm not sure how I would get the call stack. I can see it but windows does not export the log file for it, and I cant copy it from the error report window.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups