i need some help: i have something like:
word1:word2:word3:word4 ...read from a file,how can i do,when i read this line,each word delimit by ":" to put into a string....
string str1,str2,str3,str4;
str1 = word1;
...........
str4 = word4;

sorry for my english i hope eu understand

You can use getline to read from a stringstream buffer upto a delimiter, then push each word into a vector (a C++ array)

#include <string>
#include <vector>
#include <sstream>

int main()
{
    std::string line = "word1:word2:word3:word4";
    std::istringstream buffer(line);

    std::vector<std::string> words;
    std::string word;

    while( std::getline(buffer, word, ':') )
        words.push_back(word);
}

(Sorry, double post)

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.