Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » stl string and allegro text functions

This thread is locked; no one can reply to it. rss feed Print
 1   2 
stl string and allegro text functions
Rick
Member #3,572
June 2003
avatar

OK, so no, your example doesn't work. How do I increase the length of the string?

[EDIT}
+= should work I think :)
or push_back(), or maybe append()

I think that is what you were trying to get me to find :)

========================================================
Actually I think I'm a tad ugly, but some women disagree, mostly Asians for some reason.

X-G
Member #856
December 2000
avatar

Quote:

How do I increase the length of the string?

Put something on the end. Or insert at index 0, which is just at the end of the string, and not 1 index into oblivion.

--
Since 2008-Jun-18, democracy in Sweden is dead. | 悪霊退散!悪霊退散!怨霊、物の怪、困った時は ドーマン!セーマン!ドーマン!セーマン! 直ぐに呼びましょう陰陽師レッツゴー!

Rick
Member #3,572
June 2003
avatar

Oh well that's not what I expected because my index does start at 0 and that didn't work for me.

========================================================
Actually I think I'm a tad ugly, but some women disagree, mostly Asians for some reason.

ImLeftFooted
Member #3,935
October 2003
avatar

Maybe you're misinterpretting the crash.

Neil Walker
Member #210
April 2000
avatar

Quote:

Wrong language.

This is the problem when you have to code in 5 languages at once per day :)

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

Rampage
Member #3,035
December 2002
avatar

Which compiler can accept five languages at once, being java one of them? ???

-R

ImLeftFooted
Member #3,935
October 2003
avatar

Quote:

Which compiler can accept five languages at once, [java being] one of them? ???

gcc

Rampage
Member #3,035
December 2002
avatar

At once? I thought it could compile only one language at a time :P.

-R

23yrold3yrold
Member #1,134
March 2001
avatar

Quote:

How do I increase the length of the string?

resize(). reserve() is generally worthless.

--
Software Development == Church Development
Step 1. Build it.
Step 2. Pray.

Neil Walker
Member #210
April 2000
avatar

Of course, you know I meant separately. But the .NET compiler supports about 20 or so languages at present and you can mix your code if you wish.

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

piccolo
Member #3,163
January 2003
avatar

some times to get strings to work with allegro you need to convert then to a string of chars using the .c-str() example: stringName.c-str()

also when you add 2 string the have to be blank or have something in them.

example of a blank string : stringName = "";

wow
-------------------------------
i am who you are not am i

Michael Faerber
Member #4,800
July 2004
avatar

I had problems with Allegro and std::string before, and due to this I always called set_uformat(U_ASCII); once to have Allegro play well with std::string.

--
"The basic of informatics is Microsoft Office." - An informatics teacher in our school
"Do you know Linux?" "Linux? Isn't that something for visually impaired people?"

Tobias Dammers
Member #2,604
August 2002
avatar

Quote:

+= should work I think :)
or push_back(), or maybe append()

+= or +. Don't use push_back(), string inherits it from vector; this will append data after the trailing 0, which is not what you want.
And remember to cast to char so that operator += does what you want (unless you use wide characters, in which case you should use short IIRC).

string s;
/* ... */
char c = readkey() & 0xFF;
if (c >= 32)
  s += c;

That's it. If it crashes, something else is wrong.

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

Peter Hull
Member #1,136
March 2001

Quote:

Don't use push_back(), string inherits it from vector; this will append data after the trailing 0,

This is wrong (try it!)

#include <string>
#include <iostream>
using namespace std;

int main()
{
  string s;
  s.push_back('X');
  s.push_back('-');
  s.push_back('G');
  cout << s << endl;
  return 0;
}

Quote:

in which case you should use short IIRC).

Use wchar_t (string is a typedef for basic_string<char>, wstring is a typedef for basic_string<wchar_t>).

basic_string info

Pete

ImLeftFooted
Member #3,935
October 2003
avatar

std::string does not have a trailing '\0'.

Peter Hull
Member #1,136
March 2001

Quote:

std::string does not have a trailing '\0'.

I thought that too, but I checked in the include file <string> (look at note 3, below).

1// ------------------------------------------------------------
2// Class basic_string.
3 
4// Class invariants:
5// (1) [start, finish) is a valid range.
6// (2) Each iterator in [start, finish) points to a valid object
7// of type value_type.
8// (3) *finish is a valid object of type value_type; in particular,
9// it is value_type().
10// (4) [finish + 1, end_of_storage) is a valid range.
11// (5) Each iterator in [finish + 1, end_of_storage) points to
12// unininitialized memory.
13 
14// Note one important consequence: a string of length n must manage
15// a block of memory whose size is at least n + 1.

The relevant part of the standard is 21.3.4.

Pete

ImLeftFooted
Member #3,935
October 2003
avatar

Hm, interesting..

 1   2 


Go to: