-
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
-
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
Forum Rules
|
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
|
Bookmarks