69,371
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <fstream>
int main()
{
using std::cout;
using std::endl;
std::ifstream FileRd( "key.txt" );
char str[100] = { 0 };
unsigned long ulVal = 0;
while( FileRd >> str >> std::hex >> ulVal )
cout<<str<<" "<<ulVal<<endl;
return 0;
}
#include <iostream>
#include <fstream>
int main()
{
using std::cout;
using std::endl;
ifstream FileRd( "key.txt" );
char str[100] = { 0 };
unsigned long ulVal = 0;
while( FileRd >> str >> ulVal )
cout<<str<<" "<<ulVal<<endl;
return 0;
}
fstream不能格式化啊。
我这段代码怎么改成c++风格的啊
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
FILE *fp = fopen("key.txt","r");
char str[100] = { 0 };
unsigned long ulVal = 0;
while(!feof(fp))
{
fscanf(fp,"%s %x", &str, &ulVal);
cout<<str<<" "<<ulVal<<endl;
}
return 0;
}
[Quote=引用 3 楼 arong1234 的回复:]
为什么不用>>?这个不比fscanf好?
引用 2 楼 kevin820601 的回复:
晕,这个函数多好使啊,不可思议啊
[/Quote]