i'm a biginner in c++

iwant to make a programme that will take a string from the user and its length isn't limitted but each word will be separeted by either ','or';' i want to split this string in 2d or 3d array how can i do so?
Last edited on
could you show us what you did/tried?
are you trying to do it with file handling ?
To get the input you can use getline. To split the string you can use an istringstream or string::find.


Check this link out; if you're using c-style strings (or you can easily convert a std::string into a c-style string), the strtok function should work nicely:

http://www.cplusplus.com/reference/cstring/strtok/
Hi,

You can use the following syntax to split the string
getline (istream& is, string& str, char delim);

in char delim you can put the delimiter you are using in the string.
for (int i=0;i<str.length();i++)
{
int Pos = str.find('[');
string str1 =str.substr(Pos + 1, (str.find(',', 0) - pos) - 1);

int Pos2 = str.find(',');
str = str.erase(0,pos + 1);
string str2 =str.substr(0, str.find(',', 0));

int pos3 = str.find(',');
str= str.erase(0, pos3+ 1);
string str3 = str.substr(0, str.find(';', 0));

int pos4 = str.find(';');

if (pos4 == -1)
pos4 =str.find(']');

str =str.erase(0, pos4 + 1);
string str2D[100][3];

for(int j=0;j<1;j++)
{
str2D[j][0]=str1;

str2D[j][1]=str2;
str2D[j][2]=str3;
//cout<< str2D[j][0]<<str2D[j][1]<<str2D[j][2]<<"\n";


}





this is what i have done now my problem is that i want to find elements in str2D[j][2] and str3 is still unsplited what should i do?and how could i find elements in this array?
Topic archived. No new replies allowed.