0

我该怎么做?一整天我一直在到处寻找解决方案:(它在c ++中,所有问题都在标题中,谢谢

if(fp.is_open())
{
    while(getline(fp, buff))
    {
        if(buff.length() == lung)
        {
            // check if the characters are in the string

            while(found != string::npos)
            {
                cout << i << "\r";

                for(int x = 0; x < buff.length(); ++x)
                {
                    found = lettere_possibili.find(buff[x]);

                    if(found == string::npos)
                    {
                        continue;
                    }
                }

                ++i;        
            }

            j = 0;
        }

        ++k;
    }

    fp.close();
}
4

2 回答 2

5

这个问题并不完全清楚,但在我看来,您似乎正在寻找find_first_not_of()

bool containsOnlyCharsFromPossibili = (buff.find_first_not_of(lettere_possibili) == string::npos);
于 2012-11-27T20:18:40.210 回答
0
#include <iostream>

void find_chars(const std::string &first, const std::string &second)
{
    std::string::const_iterator s;

    for (s = second.begin(); s != second.end(); ++s)
    {
        if (first.find(*s) != std::string::npos)
        {
            std::cout << *s << " is in " << second << "\n";
        }
    }
}

int main()
{
    find_chars("abc", "abcdef");
}

这是输出:

a is in abcdef
b is in abcdef
c is in abcdef
于 2012-11-27T20:24:47.883 回答