У меня есть такой текстовый файл: [code]0. ----.----1----.----2----.----3----.----4 1. |Hello1 2. | Hello2 3. | Hello3 4. |Hello4 Hello5 5. | Hello6 6. | Hello7 Hello8 [/code] Я хочу считать отступы в начале строки перед любыми другими символами. Это мой код: [code]#include #include #include
using namespace std;
int main(int argc, char const *argv[]) { bool valid; int index = 0; int indent = 0; string line; ifstream file(argv[1]); while (getline(file, line)) { valid = true; while (true) { if (index >= line.length()) { break; } if (valid && line[index] == ' ') { indent++; } else if (valid && line[index] == '\t') { indent += 4; } else if (line[index] == 'H') //example for other characters { // do something with character valid = false; } index++; } cout