掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
string型のvectorに格納されたデータを数値型に変換するには? (ID:63342)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
> 読み込みの段階で数値型に格納できれば一番良いのですが 了解。 #include <iostream> #include <string> #include <sstream> #include <vector> #include <algorithm> #include <complex> int main() { std::string input = "0.0013,1.05,0.0002,0.01,0.95,0.012,0.0012,0.98,0.58824 0.3887"; std::replace(input.begin(), input.end(), ',', ' '); std::istringstream stream(input); std::vector< std::complex<double> > data; double real, imag; while ( stream >> real >> imag ) { data.push_back(std::complex<double>(real,imag)); } for ( int i = 0; i < data.size(); ++i ) { std::cout << data[i] << std::endl; } return 0; } /* 実行結果 (0.0013,1.05) (0.0002,0.01) (0.95,0.012) (0.0012,0.98) (0.58824,0.3887) */
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.