<?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[string nach const char*]]></title><description><![CDATA[<p>hab mal wieder ein problem</p>
<p>hab folgende funktion</p>
<pre><code class="language-cpp">for (std::map&lt;std::string, std::string&gt;::const_iterator i = r-&gt;params_.begin();
         i != r-&gt;params_.end();
         i++) {

       body += &quot;&lt;br&gt;&quot; + i-&gt;first + &quot; = &quot; + i-&gt;second;

       forumindex = 1;

       if(i-&gt;first == &quot;catID&quot;) 
         {body   += ForumCatIndex(body, i-&gt;second);}
    }
</code></pre>
<p>die soll der funktion ForumCatIndex die CatID übergeben (eine zweistellige zahl)</p>
<p>hier die funktion(bzw einen ausschnitt davon )</p>
<pre><code class="language-cpp">std::string ForumCatIndex(std::string body, std::string catID)
{
	char * dat_ein;
	char * token;
	char sLine[256];
	char Trenner[] = &quot;|@|&quot;;

	dat_ein = &quot;forum/cat01.txt&quot;;

	ifstream Datei(dat_ein);
</code></pre>
<p>und dort wo jetzt cat01.txt steht soll die zahl eben soll eben die zahl von der anderen funktion hin</p>
<p>das klappt bei mir aber nicht egal was ich versucht habe :<br />
habe erst der funktion versucht nicht string sondern int zu übergeben klappte nicht<br />
dann mit c-str() klappt auch nicht mit sprintf klappte nicht da char nicht zu const char konvertieren geht und die funktion ifstream geht anscheinend nur mit const char</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/117696/string-nach-const-char</link><generator>RSS for Node</generator><lastBuildDate>Fri, 21 Aug 2026 02:49:07 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/117696.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 10 Aug 2005 13:07:15 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to string nach const char* on Wed, 10 Aug 2005 13:07:15 GMT]]></title><description><![CDATA[<p>hab mal wieder ein problem</p>
<p>hab folgende funktion</p>
<pre><code class="language-cpp">for (std::map&lt;std::string, std::string&gt;::const_iterator i = r-&gt;params_.begin();
         i != r-&gt;params_.end();
         i++) {

       body += &quot;&lt;br&gt;&quot; + i-&gt;first + &quot; = &quot; + i-&gt;second;

       forumindex = 1;

       if(i-&gt;first == &quot;catID&quot;) 
         {body   += ForumCatIndex(body, i-&gt;second);}
    }
</code></pre>
<p>die soll der funktion ForumCatIndex die CatID übergeben (eine zweistellige zahl)</p>
<p>hier die funktion(bzw einen ausschnitt davon )</p>
<pre><code class="language-cpp">std::string ForumCatIndex(std::string body, std::string catID)
{
	char * dat_ein;
	char * token;
	char sLine[256];
	char Trenner[] = &quot;|@|&quot;;

	dat_ein = &quot;forum/cat01.txt&quot;;

	ifstream Datei(dat_ein);
</code></pre>
<p>und dort wo jetzt cat01.txt steht soll die zahl eben soll eben die zahl von der anderen funktion hin</p>
<p>das klappt bei mir aber nicht egal was ich versucht habe :<br />
habe erst der funktion versucht nicht string sondern int zu übergeben klappte nicht<br />
dann mit c-str() klappt auch nicht mit sprintf klappte nicht da char nicht zu const char konvertieren geht und die funktion ifstream geht anscheinend nur mit const char</p>
]]></description><link>https://www.c-plusplus.net/forum/post/849384</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/849384</guid><dc:creator><![CDATA[Skippy]]></dc:creator><pubDate>Wed, 10 Aug 2005 13:07:15 GMT</pubDate></item><item><title><![CDATA[Reply to string nach const char* on Wed, 10 Aug 2005 13:12:56 GMT]]></title><description><![CDATA[<p>Hi!</p>
<p>Du solltest dein Problem mal genauer schildern und mehr Quellcode posten. So kann ich nichts entdecken.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/849393</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/849393</guid><dc:creator><![CDATA[Stormrage]]></dc:creator><pubDate>Wed, 10 Aug 2005 13:12:56 GMT</pubDate></item><item><title><![CDATA[Reply to string nach const char* on Wed, 10 Aug 2005 13:23:00 GMT]]></title><description><![CDATA[<p>mehr hab ich leider nicht was damit zu tun hat</p>
<p>also in der map steht folgendes catID und als value z.b. 01</p>
<p>dies übergebe ich der funtkion hiermit</p>
<p>ForumCatIndex(body, i-&gt;second)</p>
<p>in der funktion selbst will ich die zahl hier als besipiel 01</p>
<p>hier reinhaben</p>
<p>dat_ein = &quot;forum/cat01.txt&quot;;</p>
<p>so nach dem motto</p>
<p>dat_ein = &quot;forum/cat&quot; + catID + &quot;.txt&quot;;</p>
<p>das klappt aber nicht und wie ich geschrieben habe hab ich schon ein paar sachen probiert aber fehlanzeige</p>
]]></description><link>https://www.c-plusplus.net/forum/post/849400</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/849400</guid><dc:creator><![CDATA[Skippy]]></dc:creator><pubDate>Wed, 10 Aug 2005 13:23:00 GMT</pubDate></item><item><title><![CDATA[Reply to string nach const char* on Wed, 10 Aug 2005 13:53:28 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">std::string ForumCatIndex(std::string body, std::string catID){
    std::string dat_ein;
    dat_ein = &quot;forum/cat&quot; + catID + &quot;.txt&quot;;
    return dat_ein;
}

int main() {
    ifstream Datei(ForumCatIndex( &quot;&quot;, &quot;01&quot;).c_str()); 
    return 0;
}
</code></pre>
<p>Funktioniert einwandfrei.</p>
<p>Skippy schrieb:</p>
<blockquote>
<p>das klappt aber nicht und wie ich geschrieben habe hab ich schon ein paar sachen probiert aber fehlanzeige</p>
</blockquote>
<p>Hast du</p>
<pre><code class="language-cpp">#include &lt;string&gt;
</code></pre>
<p>in deinem Programm? VC6 macht da ein paar wirklich lustige Fehlermeldungen wenn du &lt;fstream&gt; eingebunden hast und &lt;string&gt; fehlt.<br />
Kurt</p>
]]></description><link>https://www.c-plusplus.net/forum/post/849436</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/849436</guid><dc:creator><![CDATA[ZuK]]></dc:creator><pubDate>Wed, 10 Aug 2005 13:53:28 GMT</pubDate></item><item><title><![CDATA[Reply to string nach const char* on Wed, 10 Aug 2005 14:08:54 GMT]]></title><description><![CDATA[<p>nutze dev c++<br />
und am include liegt es nicht ist alles drin</p>
<p>wenn ich da in der funktion so abändere</p>
<pre><code class="language-cpp">char * dat_ein;
	dat_ein = &quot;forum/cat&quot; + catID + &quot;.txt&quot;;
	ifstream Datei(dat_ein);
</code></pre>
<p>dann kommt folgende fehlermeldung</p>
<p>cannot convert `std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;' to `char*' in assignment</p>
<p>wenn ich das so abändere</p>
<pre><code class="language-cpp">std::string dat_ein;
	dat_ein = &quot;forum/cat&quot; + catID + &quot;.txt&quot;;
	ifstream Datei(dat_ein);
</code></pre>
<p>dann folgende</p>
<p>no matching function for call to `std::basic_ifstream&lt;char, std::char_traits&lt;char&gt; &gt;::basic_ifstream(std::string&amp;)'</p>
<p>aus spaß mal die ganze funktion wie sie bis jetzt ist</p>
<pre><code class="language-cpp">std::string ForumCatIndex(std::string body, std::string catID)
{
    std::string dat_ein;
	char * token;
	char sLine[256];
	char Trenner[] = &quot;|@|&quot;;

	dat_ein = &quot;forum/cat&quot; + catID + &quot;.txt&quot;;

	ifstream Datei(dat_ein);

body +=&quot;&lt;center&gt;&quot;;
body +=&quot;&lt;table border='0' width='760' cellpadding='0' cellspacing='0'&gt;&quot;;
body +=&quot;&lt;tr&gt;&quot;;
body +=&quot; &lt;td class='logo' id='head' align='left'&gt;&quot;;
body +=&quot;  &lt;h1&gt;&lt;a href='http://skippy.dyndns.ws' title='Skippy - sagt: das macht spaß'&gt;SKIPPSerV - Test Forum&lt;span&gt;&lt;/span&gt;&lt;/a&gt;&lt;/h1&gt;&quot;;
body +=&quot; &lt;/td&gt;&quot;;
body +=&quot;&lt;/tr&gt;&quot;;
body +=&quot;&lt;tr&gt;&quot;;
body +=&quot;&lt;td align='left'&gt;&quot;;
body +=&quot;&lt;div class='BigPhorumForumTitle'&gt;&lt;strong&gt;SKIPPSerV Beta version Forum&lt;/strong&gt;&lt;/div&gt;&quot;;
body +=&quot;&lt;br /&gt;&quot;;
body +=&quot;&lt;table width='100%' cellspacing='0' cellpadding='3' border='0'&gt;&quot;;
body +=&quot;&lt;tr&gt;&quot;;
body +=&quot;  &lt;td width='60%' nowrap='nowrap'  bgcolor='#f2f2f2'&gt;&lt;FONT color='#267e9b' class='PhorumNav'&gt;&amp;nbsp;&lt;a href='index.php?f=0'&gt;&lt;FONT color='#267e9b' class='PhorumNav'&gt;Forum List&lt;/font&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;|&amp;nbsp;&amp;nbsp;&lt;a href='post.php?f=6'&gt;&lt;FONT color='#267e9b' class='PhorumNav'&gt;New Topic&lt;/font&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;|&amp;nbsp;&amp;nbsp;&lt;a href='search.php?f=6'&gt;&lt;FONT color='#267e9b' class='PhorumNav'&gt;Search&lt;/font&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;|&amp;nbsp;&amp;nbsp;&lt;a href='login.php?f=6'&gt;&lt;FONT color='#267e9b' class='PhorumNav'&gt;Log In&lt;/font&gt;&lt;/a&gt;&amp;nbsp;&lt;/font&gt;&lt;/td&gt;&quot;;
body +=&quot;  &lt;td align='right' width='40%'  bgcolor='#f2f2f2'&gt;&lt;div class=nav&gt;&lt;FONT color='#267e9b' class='PhorumNav'&gt;&amp;nbsp;&lt;a href='list.php?f=6&amp;t=1117391812&amp;a=2'&gt;&lt;FONT color='#267e9b' class='PhorumNav'&gt;Older Messages&lt;/font&gt;&lt;/a&gt;&amp;nbsp;&lt;/font&gt;&lt;/div&gt;&lt;/td&gt;&quot;;
body +=&quot;&lt;/tr&gt;&quot;;
body +=&quot;&lt;/table&gt;&quot;;

body +=&quot;&lt;table class='PhorumListTable' width='100%' cellspacing='0' cellpadding='0' border='0'&gt;&quot;;
body +=&quot;&lt;tr&gt;&quot;;
body +=&quot;    &lt;td class='PhorumListHeader'  bgcolor='#31a2c6'&gt;&lt;FONT color='#FFFFFF'&gt;&amp;nbsp;Topics&lt;img src='images/trans.gif' border=0 width=1 height=24 align='absmiddle'&gt;&lt;/font&gt;&lt;/td&gt;&quot;;
body +=&quot;    &lt;td class='PhorumListHeader'  bgcolor='#31a2c6' width='150' nowrap='nowrap'&gt;&lt;FONT color='#FFFFFF'&gt;Author&amp;nbsp;&lt;/font&gt;&lt;/td&gt;&quot;;
body +=&quot;    &lt;td class='PhorumListHeader' align='center'  bgcolor='#31a2c6' width='80' nowrap='nowrap'&gt;&lt;FONT color='#FFFFFF'&gt;Replies&amp;nbsp;&lt;/font&gt;&lt;/td&gt;&quot;;
body +=&quot;    &lt;td class='PhorumListHeader'  bgcolor='#31a2c6' width='120' nowrap='nowrap'&gt;&lt;FONT color='#FFFFFF'&gt;Last Post&lt;/font&gt;&lt;/td&gt;&quot;;
body +=&quot;&lt;/tr&gt;&quot;;

	if ( !Datei )
	{
		cout &lt;&lt; &quot;Kann Datei ( &quot; &lt;&lt; dat_ein &lt;&lt; &quot; ) nicht öffnen&quot; &lt;&lt; endl;
	}

	while(!Datei.eof())
	{
		Datei.getline(sLine, 256);
		cout &lt;&lt; &quot;Zeile :&quot; &lt;&lt; sLine &lt;&lt; endl;

		// Zeile auseinandernehmen.
		token = strtok(sLine, Trenner);

body +=&quot;&lt;tr&gt;&quot;;
body +=&quot;  &lt;td class='PhorumListRow'  bgcolor='#FFFFFF'&gt;&lt;FONT color='#303030'&gt;&amp;nbsp;&lt;img src='images/trans.gif' border=0 width=1 height=21 align='absmiddle'&gt;&amp;nbsp;&lt;a href='/Forum/?catID=&quot;;
body += token;//catID der url hinzufügen
body += &quot;'&gt;&quot;;
			token = strtok(NULL, Trenner);
body += token;//Titel der Kategorie
body +=&quot;&lt;/a&gt;&amp;nbsp;&lt;/font&gt;&lt;font class='PhorumNewFlag'&gt;&quot;;
			token = strtok(NULL, Trenner);
body += token;//erweiterte Nachricht z.b. Wichtig, Neu, usw
body +=&quot;&lt;/font&gt;&lt;/td&gt;&quot;;
body +=&quot;  &lt;td class='PhorumListRow' width='150'  bgcolor='#FFFFFF' nowrap='nowrap'&gt;&lt;FONT color='#303030'&gt;&lt;strong&gt;&quot;;
			token = strtok(NULL, Trenner);
body += token;//Author
body += &quot;&lt;/strong&gt;&amp;nbsp;&lt;/font&gt;&lt;/td&gt;&quot;;
body +=&quot;  &lt;td class='PhorumListRow' align='center' width='80'  bgcolor='#FFFFFF' nowrap='nowrap'&gt;&lt;FONT color='#303030' size=-1&gt;not aviable&amp;nbsp;&lt;/font&gt;&lt;/td&gt;&quot;;
body +=&quot;  &lt;td class='PhorumListRow' width='120'  bgcolor='#FFFFFF' nowrap='nowrap'&gt;&lt;FONT color='#303030' size=-1&gt;&quot;;
			token = strtok(NULL, Trenner);
body += token;//Datum
body +=&quot;&amp;nbsp;&lt;/font&gt;&lt;/td&gt;&quot;;
body +=&quot;&lt;/tr&gt;&quot;;
			token = strtok(NULL, Trenner);

		while( token != NULL )//entfernt überflüssige token um fehler zu vermeiden
		{
			cout &lt;&lt; &quot;Token = &quot; &lt;&lt; token &lt;&lt; endl;// für debug zwecke

			token = strtok(NULL, Trenner); 
		}

	}
	return body; 
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/849453</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/849453</guid><dc:creator><![CDATA[Skippy]]></dc:creator><pubDate>Wed, 10 Aug 2005 14:08:54 GMT</pubDate></item><item><title><![CDATA[Reply to string nach const char* on Wed, 10 Aug 2005 14:24:53 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">std::string dat_ein; 
dat_ein = &quot;forum/cat&quot; + catID + &quot;.txt&quot;; 
ifstream Datei(dat_ein.c_str());
</code></pre>
<p>Kurt</p>
]]></description><link>https://www.c-plusplus.net/forum/post/849480</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/849480</guid><dc:creator><![CDATA[ZuK]]></dc:creator><pubDate>Wed, 10 Aug 2005 14:24:53 GMT</pubDate></item><item><title><![CDATA[Reply to string nach const char* on Wed, 10 Aug 2005 14:25:50 GMT]]></title><description><![CDATA[<blockquote>
<pre><code class="language-cpp">std::string dat_ein; 
    dat_ein = &quot;forum/cat&quot; + catID + &quot;.txt&quot;; 
    ifstream Datei(dat_ein);
</code></pre>
</blockquote>
<pre><code class="language-cpp">std::string dat_ein; 
    dat_ein = &quot;forum/cat&quot; + catID + &quot;.txt&quot;; 
    ifstream Datei(dat_ein.c_str());
</code></pre>
<p>ifstream will ein char*</p>
]]></description><link>https://www.c-plusplus.net/forum/post/849482</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/849482</guid><dc:creator><![CDATA[YASC]]></dc:creator><pubDate>Wed, 10 Aug 2005 14:25:50 GMT</pubDate></item><item><title><![CDATA[Reply to string nach const char* on Wed, 10 Aug 2005 16:28:11 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/8069">@YASC</a> danke und ich überlege die ganze zeit warum das net klappt so war ja mein erster versuch auch dies mit nen string zu machen bin aber nicht darauf gekommen dies wieder zurückzuwandeln</p>
]]></description><link>https://www.c-plusplus.net/forum/post/849615</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/849615</guid><dc:creator><![CDATA[Skippy]]></dc:creator><pubDate>Wed, 10 Aug 2005 16:28:11 GMT</pubDate></item></channel></rss>