C++有getline()函式.
C 有 fgets(), gets() 函式.
用於讀取一行字元直到換行符,包括換行符.
char * fgets ( char * str, int num, FILE * stream );
char * gets ( char * str );
/* gets 例子 */
#include
int main()
{
char string [256];
printf ("Insert your full address: ");
gets (string);
printf ("Your address is: %s\n",string);
return 0;
}
/* fgets 例子 */
FILE * pFile;
char mystring [100];
pFile = fopen ("myfile.txt" , "r");
if (pFile == NULL) perror ("Error opening file");
else {
fgets (mystring , 100 , pFile);
puts (mystring);
fclose (pFile);
C++有getline()函式.
C 有 fgets(), gets() 函式.
用於讀取一行字元直到換行符,包括換行符.
char * fgets ( char * str, int num, FILE * stream );
char * gets ( char * str );
/* gets 例子 */
#include
int main()
{
char string [256];
printf ("Insert your full address: ");
gets (string);
printf ("Your address is: %s\n",string);
return 0;
}
/* fgets 例子 */
#include
int main()
{
FILE * pFile;
char mystring [100];
pFile = fopen ("myfile.txt" , "r");
if (pFile == NULL) perror ("Error opening file");
else {
fgets (mystring , 100 , pFile);
puts (mystring);
fclose (pFile);
}
return 0;
}