Stringy bits of rubbish.

  • Thread starter Thread starter John Swan
  • Start date Start date
J

John Swan

I am starting to really hate managed C++.



Ok.

I am trying to add a newline character to a std::string and it won't do it.

Whenever you put in << endl or + endl it wont compile because the managed
bit is shit.

If I was to put in /n or /r or /n/r and other variations it kinda works. As
in, if I display the string in a MessageBox it works fine.

However, a text box does not work.



All I get is little squares. It's as if you open a text file that works fine
in Linux but the fonts are out in Windows.


I am going insane and the MSDN is rubbish.

Cheers
 
John Swan said:
I am starting to really hate managed C++.

Ok.

I am trying to add a newline character to a std::string and it won't do it.

Whenever you put in << endl or + endl it wont compile because the managed
bit is shit.

I'm not familiar with managed C++, but I suspect there are plenty of
ways to do this elegantly. Using obscenities about the language doesn't
help, and it's likely to make people reluctant to try to help you.
If I was to put in /n or /r or /n/r and other variations it kinda works. As
in, if I display the string in a MessageBox it works fine.

However, a text box does not work.

All I get is little squares. It's as if you open a text file that works fine
in Linux but the fonts are out in Windows.

It sounds like you're getting it into the string just fine, but haven't
used the correct variation ("\r\n") for the text box. Also, have you
set the Multiline property of the TextBox to true?
 
I'm not familiar with managed C++, but I suspect there are plenty of
ways to do this elegantly. Using obscenities about the language doesn't
help, and it's likely to make people reluctant to try to help you.

Please forgive the profanity. Instead use it as a measure of how frustrating
the managed bit is.
It sounds like you're getting it into the string just fine, but haven't
used the correct variation ("\r\n") for the text box. Also, have you
set the Multiline property of the TextBox to true?

Yeah it does go into the string. Displaying that string in a messagebox does
result in it being displayed correctly.
It just wont display correctly in the text box.
Multiline is also enabled.
 
John Swan said:
Yeah it does go into the string. Displaying that string in a messagebox does
result in it being displayed correctly.
It just wont display correctly in the text box.
Multiline is also enabled.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

Here's an example (in C#) which demonstrates it working. You might want
to adapt it to C++ to test things that way:

using System;
using System.Windows.Forms;
using System.Drawing;

class Test
{
static void Main()
{
Form f = new Form();
f.Size = new Size (300, 300);

TextBox tb = new TextBox();
tb.Size = new Size (290, 290);
tb.Multiline = true;
tb.Text = "Hello\r\nThere";

f.Controls.Add(tb);
Application.Run(f);
}
}
 
Whey!!!!

Sorry, I missed a large part of the code that had \n\r! Changed that too
\r\n and it worked.

I am really not sure why it would do one thing on one control and not the
other.
I am sorry for the outburst.
But coming from a non managed C++ to this is weird. Everything is just
designed to be difficult in my opinion.
Anyway.
Thanks.

John
 
John Swan said:
Whey!!!!

Sorry, I missed a large part of the code that had \n\r! Changed that too
\r\n and it worked.

I am really not sure why it would do one thing on one control and not the
other.
I am sorry for the outburst.
But coming from a non managed C++ to this is weird. Everything is just
designed to be difficult in my opinion.

I'm sure when you get used to it you'll love it. When I have to go back
to unmanaged code every so often I'm amazed we ever managed to
accomplish what we did back in the bad old days...
 
Back
Top