1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Difference between cout and cout.write in C++

  1. Dec 18, 2011 #1
    What's the purpose of cout.write. Isn't it pretty much the same thing as cout?

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

    int main( )
    { char string[80] ;
    cout<<"Enter string\n" ;
    cin.getline(string, 80) ;
    int x1 = strlen(string) ;
    for(int i = 0 ; string != '\0' ; i++)
    if(string == ' ')
    string = '-' ;
    cout<<"The changed string is\n" ;
    cout.write(string, x1) ;
    return 0 ;
    }
     
  2. jcsd
  3. Dec 18, 2011 #2

    I like Serena

    User Avatar
    Homework Helper

    cout.write() is the public method to actually write a string.

    cout is used in an overloaded version of the << operator.
    In particular this allows you to stream any type into cout, which is not something cout.write supports.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Difference between cout and cout.write in C++
Loading...