<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[find last of]]></title><description><![CDATA[<p>Hallo, ich bin zimlich neue in C++ und möchte gerne ein Programm schreiben, das einen Ordner ausliest und HPP und CPP Dateien trennt.</p>
<p>Hier ist meine Funktion:</p>
<pre><code class="language-cpp">bool findFiles(std::vector&lt;std::string&gt;&amp; cppFiles,
			   std::vector&lt;std::string&gt;&amp; hppFiles,
			   const boost::filesystem::path&amp; path)
{
	try 
	{	
		boost::filesystem::directory_iterator end_of_dir;
		for( boost::filesystem::directory_iterator iter(path);
			 iter != end_of_dir;
			 ++iter )
		{
			if(boost::filesystem::is_regular_file(*iter))
			{
				std::string currentFile = iter-&gt;path().string();

				if( currentFile.find_last_of(&quot;.cpp&quot;) != std::string::npos ||
					currentFile.find_last_of(&quot;.cc&quot;)  != std::string::npos )
				{
					cppFiles.push_back(currentFile);
				}

				if( currentFile.find_last_of(&quot;.h&quot;)   != std::string::npos ||
					currentFile.find_last_of(&quot;.hpp&quot;) != std::string::npos )
				{
					hppFiles.push_back(currentFile);
				}
			}
		}
		return true;
	}
	catch(boost::filesystem::filesystem_error&amp; error)
	{
		std::cout &lt;&lt; &quot;Error: &quot; &lt;&lt; error.what() &lt;&lt; std::endl;
		return false;
	}
}
</code></pre>
<p>Leider kommen in beiden vectoren alle Dateien was mache ich falsch?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/306316/find-last-of</link><generator>RSS for Node</generator><lastBuildDate>Sat, 08 Aug 2026 05:25:42 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/306316.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 24 Jul 2012 21:06:09 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to find last of on Tue, 24 Jul 2012 21:06:09 GMT]]></title><description><![CDATA[<p>Hallo, ich bin zimlich neue in C++ und möchte gerne ein Programm schreiben, das einen Ordner ausliest und HPP und CPP Dateien trennt.</p>
<p>Hier ist meine Funktion:</p>
<pre><code class="language-cpp">bool findFiles(std::vector&lt;std::string&gt;&amp; cppFiles,
			   std::vector&lt;std::string&gt;&amp; hppFiles,
			   const boost::filesystem::path&amp; path)
{
	try 
	{	
		boost::filesystem::directory_iterator end_of_dir;
		for( boost::filesystem::directory_iterator iter(path);
			 iter != end_of_dir;
			 ++iter )
		{
			if(boost::filesystem::is_regular_file(*iter))
			{
				std::string currentFile = iter-&gt;path().string();

				if( currentFile.find_last_of(&quot;.cpp&quot;) != std::string::npos ||
					currentFile.find_last_of(&quot;.cc&quot;)  != std::string::npos )
				{
					cppFiles.push_back(currentFile);
				}

				if( currentFile.find_last_of(&quot;.h&quot;)   != std::string::npos ||
					currentFile.find_last_of(&quot;.hpp&quot;) != std::string::npos )
				{
					hppFiles.push_back(currentFile);
				}
			}
		}
		return true;
	}
	catch(boost::filesystem::filesystem_error&amp; error)
	{
		std::cout &lt;&lt; &quot;Error: &quot; &lt;&lt; error.what() &lt;&lt; std::endl;
		return false;
	}
}
</code></pre>
<p>Leider kommen in beiden vectoren alle Dateien was mache ich falsch?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2235389</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2235389</guid><dc:creator><![CDATA[iloveboost]]></dc:creator><pubDate>Tue, 24 Jul 2012 21:06:09 GMT</pubDate></item><item><title><![CDATA[Reply to find last of on Tue, 24 Jul 2012 21:45:10 GMT]]></title><description><![CDATA[<p>was machst find_last_of denn?</p>
<p><a href="http://www.cplusplus.com/reference/string/string/find_last_of/" rel="nofollow">C++.com</a></p>
<blockquote>
<p>Array with a sequence of characters. The last character of the string that compares equal to <strong>any</strong> of the characters in this sequence is considered a match.</p>
</blockquote>
<p>d.h. sobald auch nur ein zeichen aus deinem paramter string übergeben wird, denk er schon &quot;ja genau das will mein chef da haben...&quot;<br />
aber das willst du ja eben nicht, sondern eben der gesamte string soll vorkommen</p>
<p>für dich ist find was besser geeignet, bzw rfind(da sucht er von hinten)<br />
<a href="http://www.cplusplus.com/reference/string/string/rfind/" rel="nofollow">guckst du hier</a></p>
<p>edit:<br />
so in etwa (ist aber nicht so schön irgendwie, finde ich + ungetestet)</p>
<pre><code class="language-cpp">bool findFiles(std::vector&lt;std::string&gt;&amp; cppFiles,
               std::vector&lt;std::string&gt;&amp; hppFiles,
               const boost::filesystem::path&amp; path)
{
    try
    {   
        boost::filesystem::directory_iterator end_of_dir;
        for( boost::filesystem::directory_iterator iter(path);
             iter != end_of_dir;
             ++iter )
        {
            if(boost::filesystem::is_regular_file(*iter))
            {
                std::string currentFile = iter-&gt;path().string();

				size_t found1 = currentFile.rfind(&quot;.cpp&quot;);
				size_t found2 = currentFile.rfind(&quot;.cc&quot;);
                if( found != std::string::npos ||
                    found2 != std::string::npos )
                {
                    cppFiles.push_back(currentFile);
                }

				found1 = currentFile.rfind(&quot;.h&quot;);
				found2 = currentFile.rfind(&quot;.hpp&quot;);
                if( found1   != std::string::npos ||
                    found2 != std::string::npos )
                {
                    hppFiles.push_back(currentFile);
                }
            }
        }
        return true;
    }
    catch(boost::filesystem::filesystem_error&amp; error)
    {
        std::cout &lt;&lt; &quot;Error: &quot; &lt;&lt; error.what() &lt;&lt; std::endl;
        return false;
    }
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2235397</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2235397</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Tue, 24 Jul 2012 21:45:10 GMT</pubDate></item><item><title><![CDATA[Reply to find last of on Wed, 25 Jul 2012 07:41:35 GMT]]></title><description><![CDATA[<p>Wenn du schon boost einsetzt, dann kannst du <code>iends_with</code> benutzen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2235454</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2235454</guid><dc:creator><![CDATA[DocShoe]]></dc:creator><pubDate>Wed, 25 Jul 2012 07:41:35 GMT</pubDate></item><item><title><![CDATA[Reply to find last of on Wed, 25 Jul 2012 09:15:06 GMT]]></title><description><![CDATA[<p>Danke, iends_with ist genau das was ich wollte <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2235483</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2235483</guid><dc:creator><![CDATA[iloveboost]]></dc:creator><pubDate>Wed, 25 Jul 2012 09:15:06 GMT</pubDate></item></channel></rss>