DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  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

Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links