TextBox

Aici puteti sta la un pahar de vorba cu ceilalti membri despre orice subiect.
Post Reply
balasin
Junior
Junior
Posts: 1
Joined: 02 Jun 2012, 14:23
Judet: Dolj

TextBox

Post by balasin » 02 Jun 2012, 14:27

Salut.Am si eu o aplicatie la licenta si a trebuit sai fac interfata si nu reusesc sa fac legatura cu text box adica am facut ceva ceva dar imi apare eroarea conversion from 'wchar_t' to 'char', possible loss of data.

Code: Select all

#pragma once

#include<iostream>
#include<conio.h>
#include<fstream>
#include<vector>
#include<list>
#include<set>
#include<string>
#include<string.h>
#include<cstdlib>
#include<algorithm>
#include<iterator>
#include <windows.h>
#include <vcclr.h>
using namespace std;


namespace test3 {

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

	/// <summary>
	/// Summary for Form1
	///
	/// WARNING: If you change the name of this class, you will need to change the
	///          'Resource File Name' property for the managed resource compiler tool
	///          associated with all .resx files this class depends on.  Otherwise,
	///          the designers will not be able to interact properly with localized
	///          resources associated with this form.
	/// </summary>
	
typedef list<string> LS; //lista de statii
typedef LS::iterator ILS; //iterator pe lista de statii
typedef LS::const_iterator CILS;
typedef vector<LS> VLS; //vector pe lista de statii
typedef set<string> MS;//multime de statii
typedef MS::iterator IMS;//iterator pe multimea de statii
typedef set<size_t> MNL;//multime de numere de linii
//iterator pe multimea de linii
typedef MNL::iterator IMNL;
//variabile globale
size_t nl=0;//numarul de linii
VLS vls;//listele tuturor statiilor
string sep(" \t\n");
	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}

	protected: 
	private: System::Windows::Forms::TextBox^  textBox1;
	private: System::Windows::Forms::Label^  label1;

	private: System::Windows::Forms::Label^  label3;
	private: System::Windows::Forms::Label^  label4;
	private: System::Windows::Forms::Label^  label5;
	private: System::Windows::Forms::Button^  button1;

	private: System::Windows::Forms::TextBox^  textBox2;


void clst(const string& linie, LS& ls){
	size_t l=linie.size();
	size_t i=linie.find_first_not_of(sep,0);
	while (i>=0 && i<l){
		size_t j=linie.find_first_of(sep,i);
		if(j==string::npos) j=l;
		ls.push_back(linie.substr(i,j-i));
		i=linie.find_first_not_of(sep,j);
	}
};
//crearea unei multimi de statii de pe o linie
MS cmst (size_t nl){
	MS ms;
	for(ILS i=vls[nl].begin(); i!=vls[nl].end(); ++i)
		ms.insert(*i);
	return ms;
};
//stabileste daca o statie este in lista ls
bool eStatie(const LS& ls,const string& statie){
	for(CILS i=ls.begin(); i!=ls.end(); ++i)
		if(*i==statie) return true;
	return false;
};
//crearea unei multimi de numere de linii ce contin o statie
MNL cmnls (const string& statie){
	MNL mnl;
	for(size_t i=0; i<nl; i++){
		ILS j;
		//cauta statie in lista de statii
		if(eStatie(vls[i],statie))
			mnl.insert(i);//adauga la multime
	};
	return mnl;
};
//determinare index element in lista
int pozStatie(const LS& ls,const string& statie){
	int i=-1;
	for(CILS j=ls.begin(); *j!=statie; ++j)
		++i;
	return i;
}
//afisare traseu intre 2 statii pe o linie sspecificata
void afTraseu(const LS& ls,const string& start,const string& stop){
	LS copie(ls);
	if(pozStatie(ls,stop) < pozStatie(ls,start)) //este inapoi
		reverse_copy(ls.begin(), ls.end(),
		inserter<LS>(copie,copie.begin()));
	CILS i=copie.begin();
	while(*i!=start)
		++i;
	while(*i!=stop){
		cout << *i <<" ";
		++i;
	};
	cout << stop << endl;
};
	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container ^components;
		
#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			this->textBox1 = (gcnew System::Windows::Forms::TextBox());
			this->textBox2 = (gcnew System::Windows::Forms::TextBox());
			this->label1 = (gcnew System::Windows::Forms::Label());
			this->label3 = (gcnew System::Windows::Forms::Label());
			this->label4 = (gcnew System::Windows::Forms::Label());
			this->label5 = (gcnew System::Windows::Forms::Label());
			this->button1 = (gcnew System::Windows::Forms::Button());
			this->SuspendLayout();
			// 
			// textBox1
			// 
			this->textBox1->Font = (gcnew System::Drawing::Font(L"Comic Sans MS", 8.25F, System::Drawing::FontStyle::Italic, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->textBox1->Location = System::Drawing::Point(193, 82);
			this->textBox1->Name = L"textBox1";
			this->textBox1->Size = System::Drawing::Size(198, 23);
			this->textBox1->TabIndex = 1;
			this->textBox1->Text = L"agronomie";
			// 
			// textBox2
			// 
			this->textBox2->Font = (gcnew System::Drawing::Font(L"Comic Sans MS", 8.25F, System::Drawing::FontStyle::Italic, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->textBox2->Location = System::Drawing::Point(193, 182);
			this->textBox2->Name = L"textBox2";
			this->textBox2->Size = System::Drawing::Size(198, 23);
			this->textBox2->TabIndex = 2;
			this->textBox2->Text = L"gara";
			// 
			// label1
			// 
			this->label1->AutoSize = true;
			this->label1->Location = System::Drawing::Point(190, 292);
			this->label1->Name = L"label1";
			this->label1->Size = System::Drawing::Size(0, 15);
			this->label1->TabIndex = 4;
			// 
			// label3
			// 
			this->label3->AutoSize = true;
			this->label3->Font = (gcnew System::Drawing::Font(L"Times New Roman", 15.75F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->label3->Location = System::Drawing::Point(92, 81);
			this->label3->Name = L"label3";
			this->label3->Size = System::Drawing::Size(85, 24);
			this->label3->TabIndex = 6;
			this->label3->Text = L"Plecare:";
			// 
			// label4
			// 
			this->label4->AutoSize = true;
			this->label4->Font = (gcnew System::Drawing::Font(L"Times New Roman", 15.75F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->label4->Location = System::Drawing::Point(92, 182);
			this->label4->Name = L"label4";
			this->label4->Size = System::Drawing::Size(71, 24);
			this->label4->TabIndex = 7;
			this->label4->Text = L"Sosire:";
			// 
			// label5
			// 
			this->label5->AutoSize = true;
			this->label5->FlatStyle = System::Windows::Forms::FlatStyle::System;
			this->label5->Font = (gcnew System::Drawing::Font(L"Times New Roman", 15.75F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->label5->Location = System::Drawing::Point(190, 25);
			this->label5->Name = L"label5";
			this->label5->Size = System::Drawing::Size(54, 24);
			this->label5->TabIndex = 8;
			this->label5->Text = L"Ruta";
			// 
			// button1
			// 
			this->button1->Location = System::Drawing::Point(432, 81);
			this->button1->Name = L"button1";
			this->button1->Size = System::Drawing::Size(106, 124);
			this->button1->TabIndex = 0;
			this->button1->UseVisualStyleBackColor = true;
			this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(7, 15);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(941, 554);
			this->Controls->Add(this->label5);
			this->Controls->Add(this->label4);
			this->Controls->Add(this->label3);
			this->Controls->Add(this->label1);
			this->Controls->Add(this->textBox2);
			this->Controls->Add(this->textBox1);
			this->Controls->Add(this->button1);
			this->Font = (gcnew System::Drawing::Font(L"Comic Sans MS", 8.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->Name = L"Form1";
			this->Text = L"Form1";
			this->ResumeLayout(false);
			this->PerformLayout();

		}
		bool To_CharStar(String^ source, char*& target)
{

  int len = (source->Length+1) * 2;
  target = new char[len];
  pin_ptr<const wchar_t> wch = PtrToStringChars(source);
  return wcstombs(target, wch, len) != -1;
}
#pragma endregion
	private: System::Void comboBox1_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e) {
			 }

	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {

//citirea traseelor din  fisier
	string linie;
	ifstream in("C:\\Users/Adyy/Documents/Visual Studio 2005/Projects/test3/trasee.txt",ios::in);
	while(in.good()){
		LS ls;
		getline(in,linie);
		clst(linie,ls);//creaza lista de statii din linie
		vls.push_back(ls);//pune lista in vectorul de trasee
	};
	in.close();
	nl=vls.size()-1;

	 
	 string start,stop;
	 
	linie=textBox1->Text[8];

	linie+=" ";
	linie+=textBox2->Text[3	];
	
	 //separare statii start si stop
	size_t i=linie.find_first_not_of(sep,0);
	size_t j=linie.find_first_of(sep,i);
	//start=linie.substr(i,j-i);
	 
	
	start=linie.substr(i,j-i);
	i=linie.find_first_not_of(sep,j);
	j=linie.length();
	stop=linie.substr(i,j-i);//se verifica mai intai daca exista legaturi directe
	
	bool direct=false;
	label1->Text="Exista un traseu direct" ;
	for (int i=0; i<nl; i++)
		if(eStatie(vls[i],start)&& eStatie(vls[i],stop)){
			afTraseu(vls[i],start,stop);
			direct=true;
		};
	if(!direct){
		label1->Text="Nu exista legaturi directe!";

		//gasirea multimii statiilor de schimb(tranzit)
		MS mst;
		MNL mnl1=cmnls(start);//multimea de linii ce contine start
		MNL mnl2=cmnls(stop);//multimea de linii ce contine stop
		for(IMNL i1=mnl1.begin();i1!=mnl1.end();++i1){
			MS ms1=cmst(*i1);
			for(IMNL i2=mnl2.begin();i2!=mnl2.end();++i2){
				MS ms2=cmst(*i2);
				set_intersection(ms1.begin(),ms1.end(),
					ms2.begin(),ms2.end(),
					inserter<MS>(mst,mst.begin()));
				for(IMS i3=mst.begin();i3!=mst.end();++i3){
					afTraseu(vls[*i1],start,*i3);
					afTraseu(vls[*i2],*i3,stop);
				}
			}
		}
	}
	

			 }
private: System::Void comboBox1_SelectedIndexChanged_1(System::Object^  sender, System::EventArgs^  e) {
		 }
};
}


Problema este aici

Code: Select all

	linie=textBox1->Text[8];

	linie+=" ";
	linie+=textBox2->Text[3	];
.....Va rog frumos ajutati-ma



nedo
Junior
Junior
Posts: 32
Joined: 14 Oct 2011, 20:18
Judet: Bucureşti

Re: TextBox

Post by nedo » 02 Jun 2012, 16:46

Prima chestie,
Pune codul intre tagurile "[.code]" si "[./code]". Fara puncte.
Apoi indica linia exacta unde iti da eroarea asta.
Cel mai probabil trebuie sa transformi ceea ce ai tu tinut ca wchar_t in char.
In mod normal char ocupa 1 byte, iar wchar_t ocupa 2 sau 4 depinzand de platforma.
Avand in vedere ca folosesti c++/cli presupun ca esti pe windows deci ocupa 2 bytes.

Ai un exemplu aici despre cum sa faci transformarea intre char* si wchar_t* si invers.

neagu_laurentiu
Membru++
Membru++
Posts: 919
Joined: 23 Jul 2007, 11:32

Re: TextBox

Post by neagu_laurentiu » 02 Jun 2012, 17:12

Eu am compilat codul si nu da erori.

User avatar
Marius Bancila
Fondator
Fondator
Posts: 2344
Joined: 11 Jul 2007, 11:45
Judet: Timiş
Location: Timisoara
Contact:

Re: TextBox

Post by Marius Bancila » 02 Jun 2012, 17:29

conio.h in C++/CLI? Asta inca n-am mai vazut-o.
Marius Bancila
Fondator Codexpert, Microsoft MVP VC++
Site personal | Blog

Post Reply