I have been coding a GUI program as a MySQL database manager/utility...

The idea of the section I am focusing on is, your enter a guild's name, and it queries the database and displays the guild's info in a textbox. As a test I have used this query:

SELECT * FROM `guilds` WHERE `tag` = 'ARD'

It successfully queries the database for the guild I am testing on, and displays this in my textbox:

TAG,description,created,ranks,bank

(Those are the value from my database)

I am trying to store each value (description, TAG, so on..) to a separate char/string. I have tried using the getline and that just stores them all (on different lines) to a single char.

std::string a;
std::string b;
std::string c;

(above declared at the top)

a = string(newdelim)+string(row[i]);
stringstream stream(a);
while(getline(stream, c, ','))
{
       b = c+"\n";
}

(then goes on to write d to the texbox)

The value char "newdelim" is the delimiter, and the char "row" is the mysql row, both written into the void function.

This is the code I tried using for testing getline().

I have searched over google, the forums, and asked a few buddies on MSN, but alas, no answer to my question:
How do I use a delimiter to seperate a char/string into separate values?

Overview:
I need to split a string or char with a delimiter and store each value to a new char.
I have tried getline, and that just stores them on the same char.

Help? :)

(Sorry if I made this unclear/repeated things too much, I haven't... I haven't really slept.)

mvmalderen commented: Used code tags on first post :) +11

Recommended Answers

All 4 Replies

If I read that correctly, if I use something like that, words[number] would be each value?

If I read that correctly, if I use something like that, words[number] would be each value?

Everything between the delimiters is stored in a vector.
For example when you have this string: "first,second,third" and you set the comma as a delimiter, then you'll get a vector with these elements:

first
second
third

I don't personally use vectors all too much, but thanks! Up'd your reputation, it works fairly well for now.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.