Skip to main content
gamedev.net
🔒 Locked

std::string

Started by bjmumblingmiles 5 replies 250+ views
Original Post
bjmumblingmiles
bjmumblingmiles
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
Brian J
Koen
Koen

#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]
darookie
darookie
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.


bjmumblingmiles
bjmumblingmiles
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
Brian J
Shadowdancer
Shadowdancer
The C++ Programming Language. -- Bjarne Stroustrup

Deals pretty well with the standard library. I learned more from that book than from any other before.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.