繁体   English   中英

c ++获取文件的一部分

[英]c++ Getting a portion of a file

我怎么能跳过部分文件,然后ifstream ,直到达到一定的角色?

例如,在文本文件中,将其写为:

'SaveNameExample'
variableExample = 5;

我如何只获取不带' s的SaveNameExample,将其存储为std::string变量,然后仅从下一行获取5并将其另存为int变量?

遵循以下原则应该可以:

string s = "";
char c = '';
int i = 0;

while(getline(fstream_name, temp)){
    for(int i = 0; i < temp.length(); i++){
        if(temp[i] != "'")
            s += temp[i];
        if(temp[i] >= x || temp[i] <= y) //Where x and y are ascii values for 0 and 9, respectively
            c = temp[i];
    }
}

i = atoi(c);

这仅在某些情况下有效,但是您应该能够对其进行调整以适合您要尝试执行的操作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM