std ::stringをC++でconstchar*またはchar*に変換する方法は?
文字列クラスのc_str()メソッドを使用して、文字列の内容を含むconstchar*を取得できます。
例
#include<iostream>
using namespace std;
int main() {
string x("hello");
const char* ccx = x.c_str();
cout << ccx;
} 出力
これにより、出力が得られます-
hello
#include<iostream>
using namespace std;
int main() {
string x("hello");
// Allocate memory
char* ccx = new char[s.length() + 1];
// Copy contents
std::copy(s.begin(), s.end(), ccx)
cout << ccx;
} これにより、出力が得られます-
hello
-
C ++でCSVファイルを読み取って解析する方法は?
C ++でCSVファイルを解析するには、ライブラリを使用する必要があります。自分でファイルを読み取ると見逃す可能性がある場合が多いためです。 C ++用のBoostライブラリは、CSVファイルを読み取るための非常に優れたツールセットを提供します。たとえば、 例 #include<iostream> vector<string> parseCSVLine(string line){ using namespace boost; std::vector<std::string> vec; &n
-
C#でリストを文字列に変換する方法は?
リストを宣言します。 List < string > l = new List < string > (); 次に、リストに要素を追加します。 // elements l.Add("Accessories"); l.Add("Footwear"); l.Add("Watches"); 次に、文字列に変換します。 string str = string.Join(" ", l.ToArray()); C#でリストを文字列に変換する最終的なコードを見てみましょう- 例 using Syst