Consider a file containing Unicode words as follows
آب
آباد
آبادان
if you read right to left, the first character is " آ ".
My first requirement is to read the file line by line. This would be simple.
The second requirement is to read the file line by line from the second character of each line. the result must be something like this
ب
باد
بادان
As you know there are some solutions like std::substr to meet the second requirement but Afaik std::substr does not works well with Unicode Characters.
I need something like this
std::ifstream inFile(file_name);
//Solution for first requirement
std::string line;
if (!std::getline(inFile, line)) {
std::cout << "failed to read file " << file_name << std::endl;
inFile.close();
break;
}
line.erase(line.find_last_not_of("\n\r") + 1);
std::string line2;
//what should be here to meet my second requirement?
//stay on current line
//ignore first character and std::getline(inFile, line2))
line2.erase(line.find_last_not_of("\n\r") + 1);
std::cout<<"Line= "<<line<<std::cout; //should prints آب
std::cout<<"Line2= "<<line<<std::cout; //should prints
inFile.close();