Difference between cout and cout.write in C++

  • Context: Comp Sci 
  • Thread starter Thread starter Ilikecereal
  • Start date Start date
  • Tags Tags
    C++ Difference
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 reply · 10K views
Ilikecereal
Messages
17
Reaction score
1
What's the purpose of count.write. Isn't it pretty much the same thing as count?

For eg, the following code would work the same with count and count.write

int main( )
{ char string[80] ;
count<<"Enter string\n" ;
cin.getline(string, 80) ;
int x1 = strlen(string) ;
for(int i = 0 ; string != '\0' ; i++)
if(string == ' ')
string = '-' ;
count<<"The changed string is\n" ;
count.write(string, x1) ;
return 0 ;
}
 
Physics news on Phys.org
count.write() is the public method to actually write a string.

count is used in an overloaded version of the << operator.
In particular this allows you to stream any type into count, which is not something count.write supports.