1

だから私はファイルから読み込もうとしています。そして、行の途中やどこかに「#」がある場合は、行の残りを無視して読み続けたいと思います。これは私が持っているものです:

while(getline(pgmFile, temp))
    {
    istringstream readIn(temp);
    lines++;

    while(readIn >> convert)
    {
        //cout << temp[counter] << endl;
        if (temp.length() == 0 || temp[counter] == '#' || temp[counter] == '\r' || temp[counter] == '\n')
        {}
        else
        {/*cout << temp << endl;*/}
        if(temp.at(counter) == '\n' || temp.at(counter) == '\r')
        {}
        if(convert < 57 || convert > 40)
        {
        pixels.push_back(convert);

        }
    }

この入力ファイルの場合:

P5
4 2 
64

0 0 0 0 # don't read these: 1 1 1 1
0 0 0 0

0 で読み取る必要がありますが、# の後には何もありません。

temp は「文字列」型で、行ごとに読み取っています。

どんな助けでも大歓迎です!!!

4

2 に答える 2