Archived

This topic is now archived and is closed to further replies.

bjmumblingmiles

std::string

Recommended Posts

How do I get the individual characters from a std::string one by one? I am trying to do this for alphabetizing into a binary search tree. I''m not that great with the std lib, I usually write my own code for simple things. But now I am writing a database-type thing and I want to alphabetize the entries. I wanted to store them in a linked list...but I''m worried it will be too slow, so I am now trying to use a BST. Anyway...thats why I need to be able to parse the sentences character by character. Brian

Share this post


Link to post
Share on other sites

#include <iostream>
#include <string>

int main() {

std::string bla("Test");

for(int k=0;k < bla.size() ;k++) //in this case size==4
std::cout << bla[k] << std::endl;

}


[edited by - Koen on January 27, 2003 9:01:34 PM]

Share this post


Link to post
Share on other sites
Don''t use a binary tree, use std::map instead.
The implementation is a balanced tree (RB tree in most cases) that assures log(n) time for read/write access, deletion and insertion.
This saves you a headache from implementing your own BST and also
guarantees good performance.


Share this post


Link to post
Share on other sites
I searched online for good tutorials and/or talks with std lib...i''ve found bits and pieces but I cant find enough info...esp not about std::map. Does anyone know where I can get some info? The MSDN library is alright...but I was just wondering if there were some pages devoted to the std lib and the STL, etc

Brian

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
"Effective STL" Scott Meyers
"The C++ Standard Library: A Tutorial and Reference" Nicolai M. Josuttis

Share this post


Link to post
Share on other sites