運用C 如何讀取一行字串的指定字元

2021-07-08 22:33:56 字數 1100 閱讀 1083

1樓:泡影果果

從檔案中讀取資料,一行一行的讀取,用getline#include

fstream in;

cstring strfilename = "e:\\測試\\a.txt"; //路徑是雙斜槓

in.open(strfilename,ios::in); //ios_base::in

while( !in.eof()) //如果沒有讀到檔案結尾in.close();

2樓:水上漂湯

c還是c++?c++比c強大太多,學c++就要少用字元陣列c++版:

#include

#include

#include

using namespace std;

string readspecialword(string line, int num)

while (num--);

return str;

}int main()

3樓:阿四哥

c語言字串的學習,輸入指定字串,並且計算字串的位數

c++如何從檔案中讀取字串

4樓:匿名使用者

一般來說在c++語言中讀取txt檔案的資訊有三種方法:

1、使用c語言標準檔案i/o中的fopen()、fread()等等函式。示例如下(vc6.0下編譯通過):

#include

file*stream;

void main(void)

}2、使用c++語言中的檔案i/o中的ofstream,ifstream,fstream。示例如下(vc6.0下編譯通過):

#include

#include

#include

using namespace std;

int main ()

while (!in.eof() )

return 0;

}3、使用作業系統中的api函式,比如windows上的readfile()、openfile()等等,現在作業系統一般都具備記憶體檔案對映功能,對於大的txt檔案,一般都使用這種方式操作。

js中如何刪除某個指定字元前後的字串

var s 123456789 abc alert s.substring 0,s.indexof alert s.substring s.indexof 1,s.length var str var ipos str 123456789 abc ipos str.indexof str1 str....

求助c語言 刪除文字檔案內的指定字串

include include int main printf 待刪除的字串 gets str while fgets s,81,fin if strcmp str,s fprintf fout,s s fclose fin fclose fout return 0 1.開啟一個tmp.txt的檔案...

C語言如何實現分割字串為個單獨的字元並儲存

c語言中並沒有string型別 字串都是存在char型陣列中 c語言中有標頭檔案,可以對存在char陣列中的字串進行操作 定義字串的時候你要麼使用陣列,要麼你定義為指標,對於陣列很簡單 對於指標,那你可以對指標進行操作來取到乙個乙個的字元的。指標位址的加加 不需要專門分割,c語言裡 面本來就是用字元...