Visual Studio 2008 Express Edition ¤Ç»°Âò¥²¡¼¥à¤òºî¤í¤¦
Excel¥¨¥¯¥»¥ë¤Îcsv¥Õ¥¡¥¤¥ë¤òÆɤ߹þ¤ßÌäÂê¤ò½ÐÂꤹ¤ë
Excel¤ÇÌäÂê¤òºî¤êcsv·Á¼°¤ÇÊݸ¤¹¤ë
c++µ¯Æ°
¿·µ¬ºîÀ®¡¡¥×¥í¥¸¥§¥¯¥È¡¡Windows¥¢¥×¥ê¥±¡¼¥·¥ç¥ó
¾åµ¤Î¤è¤¦¤ËForm¥Ç¥¶¥¤¥ó¤ò¤¹¤ëButton RadioButton TextBox
OpenFileDailog¤ÈmenuStrip¤òForm¤Î¾å¤Ë¥É¥é¥Ã¥¯¤¹¤ë
Load ¤È½ñ¤¤¤¤ì¡¡¤³¤³¤ò¥¯¥ê¥Ã¥¯
Àâc++¥¹¥Æ¡¼¥È¥á¥ó¥ÈÌÀ | Basic¤È¤Î°ã¤¤ | |
¥³¥á¥ó¥Èʬ | //¼Â¹Ô¤µ¤ì¤Ê¤¤ | rem¡¡¼Â¹Ô¤µ¤ì¤Ê¤¤Ê¸ |
²þ¹Ô | ;¡¡¥»¥ß¥³¥í¥ó |
¥¨¥ó¥¿¡¼¥¡¼ |
ifʸ ==2¸Ä¤Ç= |
if(a==b) c=10; | if a=b then c=10 |
ifʸ | if(a==b) c=10; |
if a=b then |
Íð¿ô | x=rand(); |
x=rand(); £°¤«¤é£°¡¥£¹£¹£¹£¹£¹£¹£¹¤Þ¤Ç |
radioButton | if(radioButton->Cheaked==true) x=1; | if OptionButton1=True Then x=1 |
ÇÛÎó Àë¸À »ÈÍÑË¡ |
À°¿ôÇÛÎó¡¡£±¼¡¸µ |
À°¿ô¡¦¼Â¿ô¤È¤â¤Ë |
ÇÛÎó Àë¸À »ÈÍÑË¡ |
À°¿ôÇÛÎó¡¡£²¼¡¸µ int b[10][10]; a=b[x][y]; |
À°¿ô¡¦¼Â¿ô¤È¤â¤Ë dim b(10,10) a=b(x,y) |
ÇÛÎó Àë¸À
|
array<int>^b = gcnew array<int>(10); x=b(y); |
À°¿ô¡¦¼Â¿ô¤È¤â¤Ë dim b(10) a=b(y) |
ÇÛÎó Àë¸À »ÈÍÑË¡ |
array<int,2>^c = gcnew array<int,2>(2, 5); a=b(x,y); |
À°¿ô¡¦¼Â¿ô¤È¤â¤Ë dim b(10,10) a=b(x,y) |
array<array<String^>^>^ b=gcnew array<array<String^>^>(10);
|
dim a$(10,10) a$="aaaaa" |
|
¼¡¤Î¥×¥í¥°¥é¥à¤òÆþ¤ì¤ë ÀÖ»ú¤¬ÆþÎϤ·¤¿¤È¤³¤í
tdafx.h
// stdafx.h : ɸ½à¤Î¥·¥¹¥Æ¥à ¥¤¥ó¥¯¥ë¡¼¥É ¥Õ¥¡¥¤¥ë¤Î¥¤¥ó¥¯¥ë¡¼¥É ¥Õ¥¡¥¤¥ë¡¢¤Þ¤¿¤Ï
// »²¾È²ó¿ô¤¬Â¿¤¯¡¢¤«¤Ä¤¢¤Þ¤êÊѹ¹¤µ¤ì¤Ê¤¤¡¢¥×¥í¥¸¥§¥¯¥ÈÀìÍѤΥ¤¥ó¥¯¥ë¡¼¥É ¥Õ¥¡¥¤¥ë
// ¤òµ½Ò¤·¤Þ¤¹¡£
#pragma once
// TODO: ¥×¥í¥°¥é¥à¤ËɬÍפÊÄɲåإåÀ¡¼¤ò¤³¤³¤Ç»²¾È¤·¤Æ¤¯¤À¤µ¤¤¡£
#include <stdlib.h>
//¡¡Íð¿ô¤ÇɬÍ×
Form1
#pragma once
namespace santaku {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
// yh
using namespace System::IO;
//yh end
/// <summary>
/// Form1 ¤Î³µÍ×
///
/// ·Ù¹ð: ¤³¤Î¥¯¥é¥¹¤Î̾Á°¤òÊѹ¹¤¹¤ë¾ì¹ç¡¢¤³¤Î¥¯¥é¥¹¤¬°Í¸¤¹¤ë¤¹¤Ù¤Æ¤Î .resx ¥Õ¥¡¥¤¥ë¤Ë´ØÏ¢ÉÕ¤±¤é¤ì¤¿
/// ¥Þ¥Í¡¼¥¸ ¥ê¥½¡¼¥¹ ¥³¥ó¥Ñ¥¤¥é ¥Ä¡¼¥ë¤ËÂФ·¤Æ 'Resource File Name' ¥×¥í¥Ñ¥Æ¥£¤ò
/// Êѹ¹¤¹¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡£¤³¤ÎÊѹ¹¤ò¹Ô¤ï¤Ê¤¤¤È¡¢
/// ¥Ç¥¶¥¤¥Ê¤È¡¢¤³¤Î¥Õ¥©¡¼¥à¤Ë´ØÏ¢ÉÕ¤±¤é¤ì¤¿¥í¡¼¥«¥é¥¤¥ººÑ¤ß¥ê¥½¡¼¥¹¤È¤¬¡¢
/// Àµ¤·¤¯Áê¸ß¤ËÍøÍѤǤ¤Ê¤¯¤Ê¤ê¤Þ¤¹¡£
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: ¤³¤³¤Ë¥³¥ó¥¹¥È¥é¥¯¥¿ ¥³¡¼¥É¤òÄɲä·¤Þ¤¹
//
}
// yh
public:
String^ fname;
array<array<String^>^>^ TableData;
int data_no,data_x;
//yh end
private: System::Windows::Forms::Button^ button2;
public:
protected:
/// <summary>
/// »ÈÍÑÃæ¤Î¥ê¥½¡¼¥¹¤ò¤¹¤Ù¤Æ¥¯¥ê¡¼¥ó¥¢¥Ã¥×¤·¤Þ¤¹¡£
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::TextBox^ textBox1;
protected:
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::RadioButton^ radioButton1;
private: System::Windows::Forms::RadioButton^ radioButton2;
private: System::Windows::Forms::RadioButton^ radioButton3;
private: System::Windows::Forms::TextBox^ textBox2;
private: System::Windows::Forms::TextBox^ textBox3;
private: System::Windows::Forms::OpenFileDialog^ openFileDialog1;
private: System::Windows::Forms::MenuStrip^ menuStrip1;
private: System::Windows::Forms::ToolStripMenuItem^ loadToolStripMenuItem;
private:
/// <summary>
/// ɬÍפʥǥ¶¥¤¥ÊÊÑ¿ô¤Ç¤¹¡£
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// ¥Ç¥¶¥¤¥Ê ¥µ¥Ý¡¼¥È¤ËɬÍפʥ᥽¥Ã¥É¤Ç¤¹¡£¤³¤Î¥á¥½¥Ã¥É¤ÎÆâÍƤò
/// ¥³¡¼¥É ¥¨¥Ç¥£¥¿¤ÇÊѹ¹¤·¤Ê¤¤¤Ç¤¯¤À¤µ¤¤¡£
/// </summary>
void InitializeComponent(void)
{
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->button1 = (gcnew System::Windows::Forms::Button());
this->radioButton1 = (gcnew System::Windows::Forms::RadioButton());
this->radioButton2 = (gcnew System::Windows::Forms::RadioButton());
this->radioButton3 = (gcnew System::Windows::Forms::RadioButton());
this->textBox2 = (gcnew System::Windows::Forms::TextBox());
this->textBox3 = (gcnew System::Windows::Forms::TextBox());
this->openFileDialog1 = (gcnew System::Windows::Forms::OpenFileDialog());
this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());
this->loadToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->button2 = (gcnew System::Windows::Forms::Button());
this->menuStrip1->SuspendLayout();
this->SuspendLayout();
//
// textBox1
//
this->textBox1->Location = System::Drawing::Point(12, 46);
this->textBox1->Name = L"textBox1";
this->textBox1->Size = System::Drawing::Size(597, 22);
this->textBox1->TabIndex = 0;
//
// button1
//
this->button1->Location = System::Drawing::Point(71, 398);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(173, 65);
this->button1->TabIndex = 1;
this->button1->Text = L"button1";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
// radioButton1
//
this->radioButton1->AutoSize = true;
this->radioButton1->Location = System::Drawing::Point(45, 89);
this->radioButton1->Name = L"radioButton1";
this->radioButton1->Size = System::Drawing::Size(110, 19);
this->radioButton1->TabIndex = 2;
this->radioButton1->TabStop = true;
this->radioButton1->Text = L"radioButton1";
this->radioButton1->UseVisualStyleBackColor = true;
//
// radioButton2
//
this->radioButton2->AutoSize = true;
this->radioButton2->Location = System::Drawing::Point(44, 145);
this->radioButton2->Name = L"radioButton2";
this->radioButton2->Size = System::Drawing::Size(110, 19);
this->radioButton2->TabIndex = 3;
this->radioButton2->TabStop = true;
this->radioButton2->Text = L"radioButton2";
this->radioButton2->UseVisualStyleBackColor = true;
//
// radioButton3
//
this->radioButton3->AutoSize = true;
this->radioButton3->Location = System::Drawing::Point(46, 206);
this->radioButton3->Name = L"radioButton3";
this->radioButton3->Size = System::Drawing::Size(110, 19);
this->radioButton3->TabIndex = 4;
this->radioButton3->TabStop = true;
this->radioButton3->Text = L"radioButton3";
this->radioButton3->UseVisualStyleBackColor = true;
//
// textBox2
//
this->textBox2->Location = System::Drawing::Point(397, 89);
this->textBox2->Name = L"textBox2";
this->textBox2->Size = System::Drawing::Size(191, 22);
this->textBox2->TabIndex = 5;
//
// textBox3
//
this->textBox3->Location = System::Drawing::Point(395, 143);
this->textBox3->Name = L"textBox3";
this->textBox3->Size = System::Drawing::Size(193, 22);
this->textBox3->TabIndex = 6;
//
// openFileDialog1
//
this->openFileDialog1->FileName = L"openFileDialog1";
this->openFileDialog1->FileOk += gcnew System::ComponentModel::CancelEventHandler(this, &Form1::openFileDialog1_FileOk);
//
// menuStrip1
//
this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) {this->loadToolStripMenuItem});
this->menuStrip1->Location = System::Drawing::Point(0, 0);
this->menuStrip1->Name = L"menuStrip1";
this->menuStrip1->Size = System::Drawing::Size(633, 31);
this->menuStrip1->TabIndex = 7;
this->menuStrip1->Text = L"menuStrip1";
//
// loadToolStripMenuItem
//
this->loadToolStripMenuItem->Name = L"loadToolStripMenuItem";
this->loadToolStripMenuItem->Size = System::Drawing::Size(57, 27);
this->loadToolStripMenuItem->Text = L"Load";
this->loadToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::loadToolStripMenuItem_Click);
//
// button2
//
this->button2->Location = System::Drawing::Point(333, 402);
this->button2->Name = L"button2";
this->button2->Size = System::Drawing::Size(183, 57);
this->button2->TabIndex = 8;
this->button2->Text = L"button2";
this->button2->UseVisualStyleBackColor = true;
this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(8, 15);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(633, 515);
this->Controls->Add(this->button2);
this->Controls->Add(this->textBox3);
this->Controls->Add(this->textBox2);
this->Controls->Add(this->radioButton3);
this->Controls->Add(this->radioButton2);
this->Controls->Add(this->radioButton1);
this->Controls->Add(this->button1);
this->Controls->Add(this->textBox1);
this->Controls->Add(this->menuStrip1);
this->MainMenuStrip = this->menuStrip1;
this->Name = L"Form1";
this->Text = L"Form1";
this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
this->menuStrip1->ResumeLayout(false);
this->menuStrip1->PerformLayout();
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void openFileDialog1_FileOk(System::Object^ sender, System::ComponentModel::CancelEventArgs^ e) {
}
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
fname="santaku.csv";
String^ FileName = fname; // ŽÌŽ§Ž²ŽÙ̾¤ò»ØÄê
String^ CodeType = "shift_jis"; // ʸ»úŽºŽ°ŽÄŽÞ¤Ï¡¢Ž¼ŽÌŽÄJISŽºŽ°ŽÄŽÞ¤ò»ØÄê
System::Text::Encoding^ encod = System::Text::Encoding::GetEncoding(CodeType);
System::IO::StreamReader^ reader = gcnew System::IO::StreamReader(gcnew System::IO::FileStream(FileName, System::IO::FileMode::Open), encod);
String^ TextData = reader->ReadToEnd();
reader->Close();
array<String^>^ LineData = TextData->Split(gcnew array<String^>{"\r", "\r", "\r"}, StringSplitOptions::RemoveEmptyEntries);
TableData = gcnew array<array<String^>^>(LineData->Length);
for(int i = 0; i < LineData->Length; i++){
TableData[i] = LineData[i]->Split(',');
}
/*for(int i = 0; i < TableData->Length; i++){
for(int j = 0; j < TableData[i]->Length; j++){
// TableData[i][j]¤òÍѤ¤¤¿½èÍý
}
}*/
//textBox1->Text=TableData[i][j];
data_no=TableData->Length;
}
private: System::Void loadToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
OpenFileDialog^ ofdlg=gcnew OpenFileDialog();
ofdlg->Filter="Data¥Õ¥¡¥¤¥ë(*.csv)|*.csv";
if(ofdlg->ShowDialog()!=System::Windows::Forms::DialogResult::OK) return;
fname=ofdlg->FileName;
String^ FileName = fname; // ŽÌŽ§Ž²ŽÙ̾¤ò»ØÄê
String^ CodeType = "shift_jis"; // ʸ»úŽºŽ°ŽÄŽÞ¤Ï¡¢Ž¼ŽÌŽÄJISŽºŽ°ŽÄŽÞ¤ò»ØÄê
System::Text::Encoding^ encod = System::Text::Encoding::GetEncoding(CodeType);
System::IO::StreamReader^ reader = gcnew System::IO::StreamReader(gcnew System::IO::FileStream(FileName, System::IO::FileMode::Open), encod);
String^ TextData = reader->ReadToEnd();
reader->Close();
array<String^>^ LineData = TextData->Split(gcnew array<String^>{"\r", "\r", "\r"}, StringSplitOptions::RemoveEmptyEntries);
TableData = gcnew array<array<String^>^>(LineData->Length);
for(int i = 0; i < LineData->Length; i++){
TableData[i] = LineData[i]->Split(',');
}
/*for(int i = 0; i < TableData->Length; i++){
for(int j = 0; j < TableData[i]->Length; j++){
// TableData[i][j]¤òÍѤ¤¤¿½èÍý
}
}*/
//textBox1->Text=TableData[i][j];
data_no=TableData->Length;
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
// x=rand()*data_no/32767; //stdafx.h¤Ë¡¡#include <stdlib.h>ɬÍ×
// x=rand()%data_no; //stdafx.h¤Ë¡¡#include <stdlib.h>ɬÍ×
// %¤Ç¤¢¤Þ¤ê¤Î¿ô¤òµá¤á¤ÆÌäÂêÈÖ¹æ¤È¤·¤Æ¤â¤è¤¤
data_x=rand()*10/32767; //stdafx.h¤Ë¡¡#include <stdlib.h>ɬÍ×
// textBox1->Text=data_x.ToString();
textBox1->Text=TableData[data_x][0];
textBox2->Text=TableData[data_x][5];
radioButton1->Text=TableData[data_x][1];
radioButton2->Text=TableData[data_x][2];
radioButton3->Text=TableData[data_x][3];
}
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
int x,n;
if(radioButton1->Checked == true) x=1;
if(radioButton1->Checked == true) x=2;
if(radioButton1->Checked == true) x=3;
n = Convert::ToInt32(TableData[data_x][4]);
if(n==x) textBox1->Text="Àµ²ò¤Ç¤¹";
else textBox1->Text = TableData[data_x][n];
}
};
}
/*
abiko_tetu¤µ¤ó ¤è¤ê°ìÉô°úÍÑ
http://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q1122345816
*/