VC++.NET 2003 - halp - string

M

man

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
 
S

Serge Paccalin

Le samedi 25 juin 2005 à 13:28:16, man a écrit dans comp.lang.c++ :
Hello,
At first I have to warn you - I'm a newbie so don't shout me down and don't
beat me :).

You're spoiling all the fun of it...
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";

I assume 'asa' is a string too, right?
but then I can't paste it into textBox:
textBox1->Text = in;

Shouldn't you put the *string* in your textbox, rather than the
*stream*? Something like:

textBox1->Text = asa;

or:

textBox1->Text = asa.c_str();
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*' "

--
___________ 25/06/2005 14:20:20
_/ _ \_`_`_`_) Serge PACCALIN -- sp ad mailclub.net
\ \_L_) Il faut donc que les hommes commencent
-'(__) par n'être pas fanatiques pour mériter
_/___(_) la tolérance. -- Voltaire, 1763
 
D

David Lee Conley

man said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,170
Latest member
Andrew1609
Top