Need help with I/O streams.......


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Need help with I/O streams.......

  1. #1
    Damien Guest

    Need help with I/O streams.......


    I have the code for creating an a file strem and printing each word....

    #include<iostream.h>
    #include <string>
    #include<fstream>

    int main ()
    {

    string s;
    cout<<"enter a file:";
    cin>>s;
    ifstream dictionary (s.C_str());
    if (!dictionary)
    return-1;
    while(dictionary>>s)
    cout<<s<<'/n';
    }

    Now i have a question. That program displays the words from a file, but how
    do i display the words from the file all in lowercase. Like if a word New
    York would appear as new york. Can someone please help me out? Thankyou

  2. #2
    Danny Kalev Guest

    Re: Need help with I/O streams.......



    Damien wrote:
    >
    > I have the code for creating an a file strem and printing each word....
    >
    > #include<iostream.h>
    > #include <string>
    > #include<fstream>
    >
    > int main ()
    > {
    >
    > string s;
    > cout<<"enter a file:";
    > cin>>s;
    > ifstream dictionary (s.C_str());
    > if (!dictionary)
    > return-1;
    > while(dictionary>>s)
    > cout<<s<<'/n';
    > }
    >
    > Now i have a question. That program displays the words from a file, but how
    > do i display the words from the file all in lowercase. Like if a word New
    > York would appear as new york. Can someone please help me out? Thankyou


    you have to convert the string to uppercase before displaying it. You
    can use the std::transform algorithm to the do job, using the toupper()
    function:

    #include <algorithm>
    #include <cctype>

    std::transform(s.begin(), s.end(), s.begin(),
    static_cast < int(*)(int) > (toupper));

    Danny

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center