首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

C++ winform 如何不能用string类型

2013-11-13 
C++ winform怎么不能用string类型#pragma onceusing namespace Systemusing namespace System::Component

C++ winform 怎么不能用string类型

#pragma once

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

#include<iostream>
#include<string>
#include<io.h>
#include<stdio.h>

namespace TestForm {

/// <summary>
/// Form2 摘要
///
/// 警告: 如果更改此类的名称,则需要更改
///          与此类所依赖的所有 .resx 文件关联的托管资源编译器工具的
///          “资源文件名”属性。否则,
///          设计器将不能与此窗体的关联
///          本地化资源正确交互。
/// </summary>
public ref class Form2 : public System::Windows::Forms::Form
{
public:
Form2(void)
{

InitializeComponent();
//
//TODO: 在此处添加构造函数代码
//
}

protected:
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
~Form2()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::CheckedListBox^  checkedListBox1;
private: System::Windows::Forms::Button^  button1;
private: System::Windows::Forms::Button^  button2;
private: System::Windows::Forms::Button^  button3;
protected: 

private:
/// <summary>
/// 必需的设计器变量。
/// </summary>
System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
void InitializeComponent(void)
{
this->checkedListBox1 = (gcnew System::Windows::Forms::CheckedListBox());
this->button1 = (gcnew System::Windows::Forms::Button());
this->button2 = (gcnew System::Windows::Forms::Button());
this->button3 = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
// 
// checkedListBox1
// 
this->checkedListBox1->FormattingEnabled = true;
this->checkedListBox1->Location = System::Drawing::Point(12, 23);
this->checkedListBox1->Name = L"checkedListBox1";
this->checkedListBox1->Size = System::Drawing::Size(163, 244);
this->checkedListBox1->TabIndex = 0;
// 
// button1
// 
this->button1->Location = System::Drawing::Point(255, 55);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(75, 23);
this->button1->TabIndex = 1;
this->button1->Text = L"选择备份";
this->button1->UseVisualStyleBackColor = true;
// 
// button2
// 
this->button2->Location = System::Drawing::Point(255, 133);
this->button2->Name = L"button2";
this->button2->Size = System::Drawing::Size(75, 23);
this->button2->TabIndex = 2;
this->button2->Text = L"全部备份";
this->button2->UseVisualStyleBackColor = true;
// 
// button3
// 
this->button3->Location = System::Drawing::Point(255, 212);
this->button3->Name = L"button3";
this->button3->Size = System::Drawing::Size(75, 25);
this->button3->TabIndex = 3;
this->button3->Text = L"系统备份";
this->button3->UseVisualStyleBackColor = true;
// 
// Form2
// 
this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(393, 287);
this->Controls->Add(this->button3);
this->Controls->Add(this->button2);
this->Controls->Add(this->button1);
this->Controls->Add(this->checkedListBox1);
this->Name = L"Form2";
this->Text = L"Form2";
this->Load += gcnew System::EventHandler(this, &Form2::Form2_Load);
this->ResumeLayout(false);

}
#pragma endregion
private: System::Void Form2_Load(System::Object^  sender, System::EventArgs^  e) {
 int num=0;
 string path="F:\\7-Zip";
 string dirname[100]={""};
 struct _finddata_t filefind;
 string curr=path+"\\*.*";
 int done=0,i=0,j,handle;
 if((handle=_findfirst(curr.c_str(),&filefind))==-1)return;
 while(!(done=_findnext(handle,&filefind)))
 {
 //if(!strcmp(filefind.name,".."))continue;
 //for(i=0;i<layer;i++)cout<<" |-  ";


 if ((_A_SUBDIR==filefind.attrib))
 {   
 dirname[num++]=filefind.name;
 //cout<<filefind.name<<endl;
 //curr=path+"\"+filefind.name;
 //filesearch(curr,layer+1);
 }
 /*else 
 {
 cout<<filefind.name<<endl;
 }*/


 }  
 
 _findclose(handle); 
 for(j=0;j<=num;j++)
checkedListBox1->Items->Add(dirname[j]);
 }
};
}




提示我说string未定义的标识符  求指导
[解决办法]
引用:
Quote: 引用:

using namespace std;

恩   加上之后   最后checkedListBox1->Items->Add(dirname[j]);
报错说
错误1error C2664: “int System::Windows::Forms::ListBox::ObjectCollection::Add(System::Object ^)”: 不能将参数 1 从“std::string”转换为“System::Object ^”d:\项目\testform\testform\Form2.h154TestForm

再怎么弄

我从来没有写过托管C++,但是直觉告诉我,你这里不应该用std::string,去看看有没有String^这之类的东西吧。

热点排行