當前位置:首頁 » 編程語言 » c語言輸入逗號隔開

c語言輸入逗號隔開

發布時間: 2023-06-28 00:59:37

A. c語言以逗號分割字元串

#include<iostream>

#include<vector>

#include<sstream>

usingnamespacestd;

intmain()

{

strings;

vector<int>v;

cin>>s;

//將讀入的字元串轉化成is流

istringstreamis(s);

intinter;

charch;

while(is>>inter)//只能讀出is流中的一個整形讀進inter

{

v.push_back(inter);

is>>ch;//然後讀一個字元型讀進ch

}

for(inti=0;i<v.size();i++)

cout<<v[i]<<"";

cout<<endl;

return0;

}

(1)c語言輸入逗號隔開擴展閱讀

C語言的字元串按照指定字元串分割操作

#include<stdio.h>

#pragmawarning(disable:4996)

#include<stdlib.h>

intmain()

{

charstr[]="我,是,中國,程序員";

char*ptr;

char*p;

printf("開始前:str=%s ",str);

printf("開始分割: ");

ptr=strtok(str,",");

while(ptr!=NULL){

printf("ptr=%s ",ptr);

ptr=strtok(NULL,",");

}

getchar();

}

熱點內容
甘蔗苗存儲 發布:2025-07-01 21:47:03 瀏覽:664
選定文件夾 發布:2025-07-01 21:45:14 瀏覽:227
資料庫或且 發布:2025-07-01 21:40:54 瀏覽:997
pythoneve 發布:2025-07-01 21:33:49 瀏覽:142
解壓玩具怎麼做只用水就可以做 發布:2025-07-01 20:52:56 瀏覽:162
解壓放鬆室 發布:2025-07-01 20:52:43 瀏覽:126
存儲器壞了 發布:2025-07-01 20:46:11 瀏覽:513
iphone怎麼設鎖屏密碼 發布:2025-07-01 20:46:10 瀏覽:622
伺服器如何處理千萬請求 發布:2025-07-01 20:30:53 瀏覽:334
plsqldeveloperjob 發布:2025-07-01 20:29:59 瀏覽:805