<?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[Problem bei String umwandlung]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>bekomme bei folgendem Code einen Fehler (siehe unten), und zwar in der Zeile</p>
<pre><code class="language-cpp">string str_file = szFileName;
</code></pre>
<p>.</p>
<pre><code class="language-cpp">// Path of executable
TCHAR szFileName[MAX_PATH+1];
GetModuleFileName(NULL, szFileName, sizeof(szFileName) / sizeof(TCHAR));
string str_file = szFileName;
</code></pre>
<p>Fehlernachricht:</p>
<blockquote>
<p>C:/Daten/cplusplus/qt/struktur/struktur/codeinteractive.cpp:29: error: conversion from 'TCHAR [261]' to non-scalar type 'std::string' requested</p>
</blockquote>
<p>Hatte vormals sowas geschrieben:</p>
<pre><code class="language-cpp">string str_file = string(szFileName);
</code></pre>
<p>Nachdem ich Teile des Projektes in QT integriert habe, hats nicht mehr geklappt <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":-/"
      alt="😕"
    /> Woran mag das liegen? Unter Codeblocks hat es noch compiliert, ist beides gcc..</p>
<p>Vielen Dank</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/262411/problem-bei-string-umwandlung</link><generator>RSS for Node</generator><lastBuildDate>Sun, 06 Sep 2026 09:26:12 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/262411.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 05 Mar 2010 15:31:43 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Problem bei String umwandlung on Fri, 05 Mar 2010 15:33:47 GMT]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>bekomme bei folgendem Code einen Fehler (siehe unten), und zwar in der Zeile</p>
<pre><code class="language-cpp">string str_file = szFileName;
</code></pre>
<p>.</p>
<pre><code class="language-cpp">// Path of executable
TCHAR szFileName[MAX_PATH+1];
GetModuleFileName(NULL, szFileName, sizeof(szFileName) / sizeof(TCHAR));
string str_file = szFileName;
</code></pre>
<p>Fehlernachricht:</p>
<blockquote>
<p>C:/Daten/cplusplus/qt/struktur/struktur/codeinteractive.cpp:29: error: conversion from 'TCHAR [261]' to non-scalar type 'std::string' requested</p>
</blockquote>
<p>Hatte vormals sowas geschrieben:</p>
<pre><code class="language-cpp">string str_file = string(szFileName);
</code></pre>
<p>Nachdem ich Teile des Projektes in QT integriert habe, hats nicht mehr geklappt <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":-/"
      alt="😕"
    /> Woran mag das liegen? Unter Codeblocks hat es noch compiliert, ist beides gcc..</p>
<p>Vielen Dank</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1864788</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1864788</guid><dc:creator><![CDATA[2Random]]></dc:creator><pubDate>Fri, 05 Mar 2010 15:33:47 GMT</pubDate></item><item><title><![CDATA[Reply to Problem bei String umwandlung on Fri, 05 Mar 2010 15:35:53 GMT]]></title><description><![CDATA[<p>Was ist TCHAR bei dir?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1864794</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1864794</guid><dc:creator><![CDATA[Michael E.]]></dc:creator><pubDate>Fri, 05 Mar 2010 15:35:53 GMT</pubDate></item><item><title><![CDATA[Reply to Problem bei String umwandlung on Thu, 11 Mar 2010 07:32:36 GMT]]></title><description><![CDATA[<p>@ Michael<br />
Verstehe leider deine Frage nicht so recht. Wenn du meinst, ob das TCHAR UNICODE ist, dann ist die Antwort nein. Benötige es auch nur, um mit der Funktion GetModuleFileName den Pfad des Programmes herauszubekommen.</p>
<p>Habe jetzt folgenden Code:</p>
<pre><code class="language-cpp">wchar_t *szFileName = new(wchar_t);
    *szFileName = szFileName[MAX_PATH+1];

    GetModuleFileName(NULL, szFileName, sizeof(szFileName) / sizeof(wchar_t));

    string str_filetest = szFileName;

    string str_file = str_filetest.c_str();

    // find last \ and deliver path to str_path
    return str_file.substr(0,str_file.find_last_of(&quot;\\&quot;));
</code></pre>
<p>Und folgende Fehlermeldung:</p>
<blockquote>
<p>C:/Daten/cplusplus/qt/struktur/struktur/codebamfvpnrelayinteractive.cpp:41: error: conversion from 'wchar_t*' to non-scalar type 'std::string' requested</p>
</blockquote>
<p>Und wenn ich statt</p>
<pre><code class="language-cpp">string str_filetest = szFileName;
</code></pre>
<p>folgendes schreibe</p>
<pre><code class="language-cpp">string str_filetest = string(szFileName);
</code></pre>
<p>erhalte ich diese Fehlermeldung:</p>
<pre><code>C:/Daten/cplusplus/qt/struktur/struktur/projektname.cpp:42: error: no matching function for call to 'std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;::basic_string(wchar_t*&amp;)'
</code></pre>
<p>btw: Warum ist im Beispiel von Jochen Kalmbach ( <a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-158666.html" rel="nofollow">http://www.c-plusplus.net/forum/viewtopic-var-t-is-158666.html</a> ) String großgeschrieben? Bei mir funktioniert die string Funktion und Datentyp nur, wenn sie kleingeschrieben werden. Bei Einbindung der gleichen Headerdateien!? Nachtrag: offensichtlich auch nicht immer...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1865726</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1865726</guid><dc:creator><![CDATA[2Random]]></dc:creator><pubDate>Thu, 11 Mar 2010 07:32:36 GMT</pubDate></item><item><title><![CDATA[Reply to Problem bei String umwandlung on Mon, 08 Mar 2010 07:37:48 GMT]]></title><description><![CDATA[<p>2Random schrieb:</p>
<blockquote>
<p>btw: Warum ist im Beispiel von Jochen Kalmbach ( <a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-158666.html" rel="nofollow">http://www.c-plusplus.net/forum/viewtopic-var-t-is-158666.html</a> ) String großgeschrieben? Bei mir funktioniert die string Funktion und Datentyp nur, wenn sie kleingeschrieben werden. Bei Einbindung der gleichen Headerdateien!? Nachtrag: offensichtlich auch nicht immer...</p>
</blockquote>
<p>Das ist eine andere Klasse (System::String) einer anderen Programmiersprache (C++/CLI) und hat nichts mit std::string zu tun.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1865737</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1865737</guid><dc:creator><![CDATA[_matze]]></dc:creator><pubDate>Mon, 08 Mar 2010 07:37:48 GMT</pubDate></item><item><title><![CDATA[Reply to Problem bei String umwandlung on Thu, 11 Mar 2010 14:10:32 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/248">@Matze</a> Danke dir. Habe mich seit längerem darüber gewundert...</p>
<p>Und die Umwandlung von wchar_t in string funktioniert nun auch</p>
<pre><code class="language-cpp">wchar_t szFileName[MAX_PATH] = L&quot;&quot;;

    GetModuleFileName(NULL, szFileName, sizeof(szFileName) / sizeof(wchar_t));

    // umwandeln in wstring
    wstring str_filetest = wstring(szFileName);

    // umwandeln von wstring in string
    // beruecksichtigt codepage nicht
    string str_file(str_filetest.begin(), str_filetest.end());
    str_file.assign(str_filetest.begin(), str_filetest.end());
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1867524</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1867524</guid><dc:creator><![CDATA[2Random]]></dc:creator><pubDate>Thu, 11 Mar 2010 14:10:32 GMT</pubDate></item></channel></rss>