Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9148005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:09:06+00:00 2026-06-17T11:09:06+00:00

I am new to C++. I am trying to make a program in C++,

  • 0

I am new to C++. I am trying to make a program in C++, but I get an error, when I use e.what(). I’ve included #include <exception>, but I get error C2664 - Cannot convert parameter 1 from const char* to system::string ^.

Here’s the code.

#pragma once
#include <iostream>
#include <fstream>
#include <exception>
#include <string>

namespace SilverthorneTechnologiesSchoolDashboard {

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace std;

//Form parameters

#pragma endregion
private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
        ifstream codeFile;
        try{
            codeFile.open("userDetails.info");
        }
        catch (exception &e)
        {
            label1->Text = e.what();
        }
         }
 };
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T11:09:08+00:00Added an answer on June 17, 2026 at 11:09 am

    codeFile is unmanaged code, throwing an unmanaged exception, so you’re catching the exception properly. All you need to do is convert the const char * to a String^ to put it in your UI.

    The String class has a constructor that takes a char* (char* is SByte* in C#). label1->Text = gcnew String(e.what()); should solve your problem.

    That said, you could use the managed stream objects. This would give you managed exceptions instead of unmanaged, and greater interoperability with the rest of your managed code. Take a look at FileStream, and see if that meets your needs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im trying to use this method to make my characters but i get the
im trying to use this method to make my characters but i get the
I am trying to make a simple program that could open a new activity
I'm new to iPhone programming, and I'm trying to make a simple program without
I'm new to C++ and trying to make two simple functions, but something goes
I'm trying to use the new(ish) AS3 global error handling class. I am trying
I'm trying to make a simple program to test the new .NET async functionality
I'm completely new to Python and I've been trying to make a fibonacci program
I am trying to compile my program on my new server, but it's not
Hello I am trying to make a C# program that downloads files but I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.