I have a list formatted like - String : Int, how would i seperate each one into individual strings?
I can't seem to figure out the separation part where it reads one space before the colon and one space after.
I have a list formatted like - String : Int, how would i seperate each one into individual strings?
I can't seem to figure out the separation part where it reads one space before the colon and one space after.
If I'm understanding right, you can read the file line by line, then separate the two elements you want with strtok() (if you're using null-terminated byte strings) or a combination of find() and substr() (if you're using std::strings)
I've worked with the former, so I'll explain what I'd do.
first, I'll read the whole line to a char array:
#include <cstring>
char temp[256];
cin.getline(temp, 256);
then, with strtok I split the line into what you need
char str[256], num[256]
char *p = strtok(temp, ":");
strcpy(str, p);
p = strtok(NULL, ":");
strcpy(num, p);
Make sure to change cin to whatever your file variable is named.
string aStr;
char split;
int aInt;
while (ifs >> aStr >> split >> aInt) {
// Dealing with these variables
}
Hope it helps