By the way,try to compile the test programs(two programs) from Makoto WATANABE was successfully,but both printed unrecognized characters in console in my code local(cp935).
Appreciated if let me know how to modify the programs both to print correctly.
FreeBasic containers (map , vector , list , queue , stack , hashtable)
Re: FreeBasic containers (map , vector , list , queue , stack , hashtable)
Code: Select all
Dim As TVECTORLONG Ptr pv = New TVECTORLONG(2) 'size = 2
...
pv->insert(2,3) 'size = 3
...
v.push_back(10) 'size = 4
...
STACK - try like this:
Code: Select all
#include "STACK.bi"
Type WSTRP as Wstring ptr
MStackTemplate(WSTRP)
Dim ps As TSTACKWSTRP
ps.push("字符串1")
ps.push("字符串2")
ps.push("字符串3")
? "Size stack="; ps.size()
? *ps.pop()
? *ps.pop()
? *ps.pop()
? "Size stack="; ps.size()
sleep
Re: FreeBasic containers (map , vector , list , queue , stack , hashtable)
Code: Select all
Dim As TVECTORLONG Ptr pv = New TVECTORLONG(2) 'size = 2
...
pv->insert(2,3) 'size = 3
...
v.push_back(10) 'size = 4
...
Yes,that's my question.Now I noticed the "out of range" message printed by the console indicates testvector(),not teststack() which I oversaw yesterday.I may have misunderstood your question number 3. I thought you were asking about memory allocation. So memory allocation is carried out as needed, and the number of cells always increases with calls insert , push_back
The output is as below.
STACK - try like this:
Code: Select all
#include "STACK.bi" Type WSTRP as Wstring ptr MStackTemplate(WSTRP) Dim ps As TSTACKWSTRP ps.push("字符串1") ps.push("字符串2") ps.push("字符串3") ? "Size stack="; ps.size() ? *ps.pop() ? *ps.pop() ? *ps.pop() ? "Size stack="; ps.size() sleep
Code: Select all
Size stack= 3
?????????3
?????????2
?????????1
Size stack= 0
Code: Select all
sub adds(psz as zstring ptr)
? Len(*psz)
? *psz
End Sub
dim as string s
s = "字符串1"
? Len(s)
? s
adds(strptr(s))
sleep
Re: FreeBasic containers (map , vector , list , queue , stack , hashtable)
Update:
The original code (bare string version) works well when the source file is in ansi format,not in UTF8;
The wstring ptr vesion can show asian character in the console but it seems the words are overlapped when source file is in ansi format.Changing to zstring ptr works well,still,in ansi format,not utf8.
ANSI,string version---OK
ANSI,zstring ptr version---OK
We'd better to find a solution for UTF8 or universal way since the majority of the source code (especially in an IDE) is UTF8.Using CodeBlocks with MinGW in C/C++ I encountered the similiar issue,providing an compiler option to the compiler helps.But I don't know how to achieve the same result in FB.
Appreciated for the great container library and for the help.
The original code (bare string version) works well when the source file is in ansi format,not in UTF8;
The wstring ptr vesion can show asian character in the console but it seems the words are overlapped when source file is in ansi format.Changing to zstring ptr works well,still,in ansi format,not utf8.
ANSI,string version---OK
Code: Select all
#include "STACK.bi"
Type WSTRP as string
MStackTemplate(WSTRP)
Dim ps As TSTACKWSTRP
ps.push("字符串1")
ps.push("字符串2")
ps.push("字符串3")
? "Size stack="; ps.size()
? ps.pop()
? ps.pop()
? ps.pop()
? "Size stack="; ps.size()
sleep
Code: Select all
#include "STACK.bi"
Type WSTRP as zstring ptr
MStackTemplate(WSTRP)
Dim ps As TSTACKWSTRP
ps.push("字符串1")
ps.push("字符串2")
ps.push("字符串3")
? "Size stack="; ps.size()
? *ps.pop()
? *ps.pop()
? *ps.pop()
? "Size stack="; ps.size()
sleep
Code: Select all
-finput-charset=UTF-8
-fexec-charset=GBK
Re: FreeBasic containers (map , vector , list , queue , stack , hashtable)
Unfortunately with encodings I can't help you. My console can't output Chinese characters. But in any case, this is a problem of encodings, not of the Containers library. A simple example (can save as UTF-16le or UTF-8 BOM ):
Code: Select all
#define unicode
#include "windows.bi"
#include "STACK.bi"
Type WSTRP as Wstring ptr
MStackTemplate(WSTRP)
Dim ps As TSTACKWSTRP
ps.push("字符串1")
messagebox(0,*ps.pop(),"",0)
-
- Posts: 8586
- Joined: May 28, 2005 3:28
- Contact:
Re: FreeBasic containers (map , vector , list , queue , stack , hashtable)
Thank you,will get a copy of this library and start to learn.D.J.Peters wrote: ↑Sep 29, 2022 10:06 Only as Info with FBTrueType you can print wstring in any language with FreeBASIC also.
Joshy