i'm new to c++ and i was trying to create a program that reads file called symbols.txt, then it fills a vector with the symbols, then i wanted to take a chars that are in range [d;p] and move them to the second vector while erasing them in the first one.
int main(){ vector<char> sym1; vector<char> sym2; int p = 100, d = 80; char x; ifstream symbols("symbols.txt"); while (symbols >> x ) { sym1.push_back(x); } for(int i = 0; i<sym1.size();i++){ if(sym1[i] < p && sym1[i] > d){ sym2.push_back(sym1[i]); sym1.erase(sym1.begin()+i); } } }
when i do this the program works if there are no same characters, otherwise it only moves half of them and leaves other half untouched. its 5 in the morning and im still trying to figure this out :(
https://stackoverflow.com/questions/66020118/c-moving-characters-from-one-vector-to-another February 03, 2021 at 09:43AM
没有评论:
发表评论