#include <stdio.h>
void main( void )
{
FILE *fp = NULL;
if ((fp = fopen("test.txt", "r")) == NULL)
{
printf("open error!\n");
}
char str[128] = {0};
char ch = 0;
fscanf(fp, "%*s\n");
fscanf(fp, "%s\n", str);
printf("%s", str);
fclose(fp);
}
丢弃一行
fscanf(fp, "%*s\n");
读一行,丢弃换行符
fscanf(fp, "%s\n", str);
c++的输入输出流
#include <locale>
#include <iostream>
struct commactype : std::ctype<char>
{
commactype(): std::ctype<char>(get_table()) {}
static std::ctype_base::mask const* get_table ()
{
static std::ctype_base::mask* rc = 0;
if (rc == 0)
{
rc = new std::ctype_base::mask[std::ctype<char>::table_size];
std::fill_n(rc,std::ctype<char>::table_size,std::ctype_base::mask());
rc['!'] = std::ctype_base::space;
rc[' '] = std::ctype_base::space;
rc['\n'] = std::ctype_base::space;
}
return rc;
}
};
int main (int,char**)
{
std::string a,b,c;
std::cin.imbue(std::locale(std::locale(),new commactype));
std::cin >> a >> b >> c;
std::cout << a << " " << b << " " << c << std::endl;
return 0;
}