cout语句中'\n'与endl的作用有什么区别没有?
它们之间有什么区别呢?以下程序原本输出为:
how about the story?
its very interesting.
为什么不是:
its very interesting.
how about the story?
但是把"\n"改为endl后输出为:
its very interesting.
how about the story?
程序:
#include "string.h"
#include "stdio.h"
#include "iostream.h"
class cstr
{
char data[100];
public:
void showme(void)
{cout<<"its very interesting."<<"\n";} ////////把"\n"改为endl它们有什么不同呢?
char *get(void);
int getlength(void);
void cpy(char *s);
void cat(char *s);
};
void main(void)
{
cstr string1,string2;
string1.showme();
string1.cpy("how about ");
string2.cpy("the story?");
string1.cat(string2.get());
puts(string1.get());
}
char *cstr::get(void)
{
return data;
}
int cstr::getlength(void)
{
return strlen(data);
}
void cstr::cpy(char *s)
{
strcpy(data,s);
}
void cstr::cat(char *s)
{
strcat(data,s);
}