將逗號分隔的字串(陣列)取出存到陣列中

2021-10-23 22:12:19 字數 650 閱讀 1054

#include

#include

#include

#include

using

namespace std;

/*將包含有逗號的字串分隔出來

將所有的逗號或者其他標點符號替換成空格,然後利用istringstream將字串或者數值存下來。

*/int

main()

istringstream m

(str)

;//m接收字串,名字隨便取

string str_s;

//存每乙個分隔出來的小字串

int str_int;

//存每乙個分隔出來的小數值字串

vector arr;

while

(m >> str_s)

//從m中將整數給str_s

for(

int i =

0; i < arr.

size()

; i++

) cout << arr[i]

<<

' ';

cout << endl;

system

("pause");

return0;

}

陣列轉字串使用逗號分隔

listdocentrys string.join docentrys public static string join string separator,ienumerablevalues public static string join string separator,ienumerabl...

myBatis通過逗號分隔字串,foreach

前言 當資料庫裡儲存的值是以逗號分隔格式儲存的字串時。資料格式如下 idname ids 1張三 b2李四e 我們拿到的條件引數是 b,e 1.後台通過逗號分隔陣列,生成查詢語句 select from table where ids in b e select id getsimilarity p...

shell將字串分隔成陣列

bin bash a hello,world,nice,to,meet,you 要將 a分割開,先儲存舊的分隔符 old ifs ifs 設定分隔符 ifs 如下會自動分隔 arr a 恢復原來的分隔符 ifs old ifs 遍歷陣列 for s in do echo s done 變數 ifs儲...