จะรับอักขระของตำแหน่งเฉพาะจากสตรีมใน c ++ ได้อย่างไร

ฉันมีไฟล์ข้อความที่มีสตริงเหล่านี้

adsklfjas;alfkjalkdsjfaldks;sjf

ฉันจะได้ตัวละครตัวที่ 10 ได้อย่างไร? ฉันรู้ตำแหน่ง (10) แต่ฉันจะวางตำแหน่งตัวเองไปที่นั่นได้อย่างไร?

int main()
{
    fstream stream("mytext.txt", fstream::in);

    char c;
    // cout << c << endl;
}

person kaytie harun    schedule 26.01.2019    source แหล่งที่มา
comment
ลองดูที่ifstream::seekg.   -  person Aziuth    schedule 26.01.2019


คำตอบ (1)


เข้าใจแล้ว.

int main()
{
    fstream stream("test.txt", fstream::in);

    char c;
    stream.seekg(10);
    stream.get(c);
    cout << "c " << stream.tellg() << " : " << c << endl;
}
person kaytie harun    schedule 26.01.2019