當前位置:首頁 » 編程語言 » 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-04-23 06:05:25 瀏覽:721
換手機怎麼把安卓app移到蘋果手機 發布:2025-04-23 06:05:20 瀏覽:898
java的時間格式 發布:2025-04-23 06:04:39 瀏覽:974
美團安卓哪裡再次配送 發布:2025-04-23 05:56:07 瀏覽:978
油畫價格演算法 發布:2025-04-23 05:54:37 瀏覽:532
交作業怎麼打開ftp 發布:2025-04-23 05:42:32 瀏覽:499
編譯的代碼怎麼生成程序 發布:2025-04-23 05:41:08 瀏覽:21
asp新聞發布源碼 發布:2025-04-23 05:39:27 瀏覽:30
vba與資料庫 發布:2025-04-23 05:38:10 瀏覽:779
上傳網監 發布:2025-04-23 05:33:57 瀏覽:262