我正在尝试在 c++/CLI 应用程序中声明一个字符串变量。
我的声明如下:
String^ strRptPath = "C:\Reports\NorthwindCustomers.rpt";
我有这个错误:
error C2059: syntax error : '^'
error C2238: unexpected token(s) preceding ';'
我也试过这个方法:
String^ strRptPath =gcnew String("C:\Reports\NorthwindCustomers.rpt");
它返回相同的错误。
整个代码是:
#pragma once
namespace CRViewerXI
{
using namespace System;
using namespace System::Text;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace CrystalDecisions::Windows::Forms;
public __gc class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
}
protected:
void Dispose(Boolean disposing)
{
if (disposing && components)
{
components->Dispose();
}
__super::Dispose(disposing);
}
private:
CrystalDecisions::Windows::Forms::CrystalReportViewer *CRViewer;
System::ComponentModel::Container * components;
private : String^ strRptPath =gcnew String("C:\\Reports\\NorthwindCustomers.rpt");
void LoadReport()
{
}
void InitializeComponent(void)
{
CRViewer = new CrystalDecisions::Windows::Forms::CrystalReportViewer();
CRViewer->ActiveViewIndex = -1;
CRViewer->ShowGroupTreeButton = true;
CRViewer->ShowExportButton = true;
CRViewer->EnableToolTips = true;
CRViewer->DisplayToolbar = true;
CRViewer->Dock = System::Windows::Forms::DockStyle::Fill;
Controls->Add(CRViewer);
this->AutoScaleBaseSize = System::Drawing::Size(5, 13);
this->ClientSize = System::Drawing::Size(528, 394);
this->Name = S"Form1";
this->Text = S"Form1";
this->Load += new System::EventHandler(this, Form1_Load);
}
private: System::Void Form1_Load(System::Object * sender, System::EventArgs * e)
{
}
};
}
我做错了吗?这是我第一次在托管 C++ 中工作。
谢谢。