"man" <pi*************@poczta.onet.pl> wrote in message
news:d9**********@news.onet.pl...
Hello,
At first I have to warn you - I'm a newbie so don't shout me down and
don't
beat me :).
I have a few problems concerning programming using VC++ .NET Std 2003
(particularly Windows Forms):
1) I do not know how to take text fram a text file and paste it into a
textBox. I can do it like that:
ifstream in("teksttt.txt");
ofstream out("teksttt.txt");
string linia;
while(getline(in,linia))
asa += linia + "\n";
but then I can't paste it into textBox:
textBox1->Text = in;
It shows a problem/error:
"error C2664: 'void System::Windows::Forms::TextBox::set_Text(System::
String__gc*)' : cannot convert parameter 1 from 'std::ifstrem' to
'System::String__gc*' "
How to convert 'string' into other one to make possible pasting it into a
textBox?
What type should I use?
2) I have to paste the text like this one:
"There are n men and m women.":
"There are " + n.ToString + " men and " + m.ToString " women."
Am i right?
Thanks in advance...
man
The problem you're having appears to be that you're trying to program
standard C++ (called unmanaged code in VC.NET) in a .NET project (managed
code). I only just started learning VC++ .NET 2003 last week, but here's
some code to help you open and read a text file and assign the data straight
to a text box:
System::IO::StreamReader* myFile;
myFile = System::IO::File::OpenText("teksttt.txt");
this->textBox1->Text = myFile->ReadLine();
ini->Close();
If you want to perform string concatenation while reading a file before
assigning it to a text box, you need the following:
System::Text::StringBuilder* linia = new System::Text::StringBuilder();
// do your file stuff here and start your loop
linia->Append(myFile->ReadLine());
// end of your loop
this->textBox1->Text = linia->ToString();
You can also do the following to replace parameters in a string with values
from variables:
linia->Append("There are {0} men and {1} women.", menvariable.ToString(),
womenvariable.ToString());
Hope this helps.
Dave