February 17,2006

c++ 使用讀檔

以下範例是使用c++ 去讀檔

void test(){


string str;
string ansi,temp;
ifstream fin;
int len;
fin.open("config.ini");
const char* pszConverted;
if(fin.is_open()){
fin.clear();

int count =0;
while(getline(fin,str)){
pszConverted = str.c_str();
ansi = string(pszConverted); // convert string to AnsiString
len = ansi.length();

if(count == 0){
cout << count << ansi << "\n";
}
count++;

}//end while


}else{

cout << ("Miss");
}
fin.close();
}

Posted by yam_javanull at 樂多Roodo! │21:38 │回應(1)引用(0)C++
樂多分類:網路/3C 共同主題:程式設計 工具:編輯本文
Ads by Roodo! 

引用URL

http://cgi.blog.roodo.com/trackback/1136766
回應文章
可以在 while() loop 裡加一個 count 然後用 if 去判決 line number
Posted by java at February 18,2006 18:59