Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- bool IsDigit(char c) {
- return c >= '0' && c <= '9';
- }
- // Возвращает число с позиции cursor
- int ReadInt(const string& s, int& cursor) {
- // 234,6sd,98224980,
- // ^ ^
- // cursor new_cursor
- int result = 0;
- while (IsDigit(s[cursor])) {
- int digit = s[cursor] - '0';
- result = result * 10 + digit;
- ++cursor;
- }
- return result;
- }
- int main() {
- string s;
- getline(cin, s);
- int cursor = 0;
- int value = ReadInt(s, cursor);
- cout << "Value = " << value << endl;
- cout << "Cursor = " << cursor;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement