VC++.NET 2003 - halp - string

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • man

    VC++.NET 2003 - halp - string

    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.tx t");

    string linia;

    while(getline(i n,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::TextBo x::set_Text(Sys tem::
    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

  • Serge Paccalin

    #2
    Re: VC++.NET 2003 - halp - string

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

    You're spoiling all the fun of it...
    [color=blue]
    > 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.tx t");
    >
    > string linia;
    >
    > while(getline(i n,linia))
    >
    > asa += linia + "\n";[/color]

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

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

    textBox1->Text = asa;

    or:

    textBox1->Text = asa.c_str();
    [color=blue]
    > It shows a problem/error:
    > "error C2664: 'void System::Windows ::Forms::TextBo x::set_Text(Sys tem::
    > String__gc*)' : cannot convert parameter 1 from 'std::ifstrem' to
    > 'System::String __gc*' "[/color]

    --
    ___________ 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

    Comment

    • David Lee Conley

      #3
      Re: VC++.NET 2003 - halp - string


      "man" <pizzazzBEZSPAM U@poczta.onet.p l> wrote in message
      news:d9jf44$ofr $1@news.onet.pl ...[color=blue]
      > 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.tx t");
      >
      > string linia;
      >
      > while(getline(i n,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::TextBo x::set_Text(Sys tem::
      > 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
      >[/color]

      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::Str eamReader* myFile;
      myFile = System::IO::Fil e::OpenText("te ksttt.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::S tringBuilder* linia = new System::Text::S tringBuilder();

      // do your file stuff here and start your loop

      linia->Append(myFil e->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("Ther e are {0} men and {1} women.", menvariable.ToS tring(),
      womenvariable.T oString());

      Hope this helps.

      Dave


      Comment

      • man

        #4
        Re: VC++.NET 2003 - halp - string

        > Hope this helps.

        Thank you very much. I'll check it up.
        [color=blue]
        > Dave[/color]

        me :)

        Comment

        Working...