前提・実現したいこと
csvファイルを読み込み、UE4へfloat型もしくは文字列で数値を送りたいです。
なお、BlueprintFuctionLibraryで関数としてノードになってほしいです。
自分の考えとしては、
①vector<string>をFStringで送付できるようにする
②vector<string>→vector<float>へ変換し、return float(strvec[Count]);でUE4へ送る
なのですが、ネットで調べてみても実現方法がわかりません。
発生している問題・エラーメッセージ
エラー (アクティブ) E0020 "std::string" から "const char *" への適切な変換関数が存在しません エラー (アクティブ) E0165 関数呼び出しの引数が少なすぎます
↑return float(std::strtof(strvec.at(Count21)));の部分でエラーが出ています
該当のソースコード
h
1// Fill out your copyright notice in the Description page of Project Settings. 2 3#pragma once 4 5#include "CoreMinimal.h" 6#include "Kismet/BlueprintFunctionLibrary.h" 7#include "MyBlueprintFunctionLibrary.generated.h" 8 9/** 10 * 11 */ 12UCLASS() 13class UMyBlueprintFunctionLibrary : public UBlueprintFunctionLibrary 14{ 15 GENERATED_BODY() 16 17 UFUNCTION(BlueprintCallable, Category = "MyBPLibrary") 18 static float Csv(const int& Count); 19}
ccp
1// Fill out your copyright notice in the Description page of Project Settings. 2 3 4#include "MyBlueprintFunctionLibrary.h" 5 6#include <fstream> 7#include <iostream> 8#include <vector> 9#include <sstream> 10 11using std::cout; using std::cerr; 12using std::endl; using std::string; 13using std::ifstream; using std::vector; 14using std::ostringstream; using std::istringstream; 15 16vector<string> split(string& input, char delimiter) { 17 istringstream stream(input); 18 string field; 19 vector<string> result; 20 while (std::getline(stream, field, delimiter)) { 21 result.push_back(field); 22 } 23 return result; 24} 25 26float UMyBlueprintFunctionLibrary::Csv(const int& Count) { 27 string filename("csvが入っているデータのpath"); //ファイルのパス指定 28 vector<string> strvec; 29 30 ifstream input_file(filename); //指定したファイルを開く 31 if (!input_file.is_open()) { //ファイルが開かなかったとき 32 cerr << "Cannot open the file - '" << filename << "'" << endl; //コメント表示 33 return EXIT_FAILURE; //プログラムが異常終了したことを表す 34 } 35 36 string line; 37 while (std::getline(input_file, line)) { //csvファイルの最後の行までループを回す 38 strvec = split(line, ','); //カンマ区切りで配列に格納 39 } 40 41 return float(std::strtof(strvec.at(Count))); 42}
試したこと
①stringと書かれたすべてコードをFStringに変えてみる ←うまく反応していたコードが続々とエラーになりました
②strtofでstringからfloatへ変えてみる
どれも失敗しました。
補足情報(FW/ツールのバージョンなど)
UE4:4.27.2
Visual Studio:2022
①vector<string>をFStringで送付できるようにする
②vector<string>→vector<float>へ変換し、return float(strvec[Count]);でUE4へ送る
以外でもこういう方法なら出来るなど小さいことでもよいので、あればアドバイス頂きたいです。
csv読み込みの参考ページは以下URLです。
https://cvtech.cc/readcsv/
C++、UE4、プログラミング初心者のため、お手数ではありますが、丁寧なご説明までいただけたら大変ありがたいです。
ご不明な点等ございましたらご質問頂ければ幸いです。
お手数ではありますが、よろしくお願いいたします。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/02/21 05:12
2022/02/21 05:19
2022/02/21 11:28
2022/02/21 12:19
2022/02/22 05:41
2022/02/22 06:37
2022/02/23 00:11