Solved

String

Posted on 2000-05-05
9
245 Views
Last Modified: 2010-04-02
#include<iostream>



#include<string>



#include<fstream>





/*This program is in charge of the search done by location.

What it does is that if the user enters the name of the town

it open that town file,if that file exists and printouts all

the info in that file*/



/*This file is missing the CGI manipulation stuff*/





main()



{



using namespace std;

/*something goes here so that what is entered in the form is processed

and the assigned to the string townName, so it can be used by the

program*/



string townName, x("mayaguez"), y("aguada"), z("aguadilla"), a("rincon"), b("cabo rojo");



cout<< "Enter the name of the town: "<<endl; //This is for purpose of testing program



getline(cin,townName);



townName=strlwr(townName.c_str());




if (townName==x||townName==y||townName==z||townName==a||townName==b)



{



townName+=string(".txt");



fstream in(townName.c_str(),ios::in);

    if(!in)

    {

       /*if this happens the user should be sent to a page

       that tells to hit back button and start search again*/

       

       cout<<"The file does not exist\n";

       return 0;

    }

    string read;

    while(!in.eof())

    {

       getline(in,read);

       

       /*This are the results of this search which have to

       be output to the screen.If possible a link should be

       provided to a page with restaurant menu*/

       

       cout<<read<<"\n";

    }







}



return 0;



}


I am having problems with this line. It does not compile. Whats wrong?

townName=strlwr(townName.c_str());
0
Comment
Question by:milalik
  • 6
  • 2
9 Comments
 
LVL 3

Expert Comment

by:Laminamia063099
Comment Utility
strlwr is not an ANSI-C function (it's found in some compiler libraries, but not all).  Use the function tolower to convert a char * to it's lower case representative.

To do this, include <ctype.h>

If you have trouble, leave another comment :)

Laminamia :)
0
 

Author Comment

by:milalik
Comment Utility
I want to deal with string not characters.


can you also view my other question and give some advice
thanx
0
 

Author Comment

by:milalik
Comment Utility
Need help converting the string in all lowercase
0
 
LVL 3

Expert Comment

by:Laminamia063099
Comment Utility
If you need to deal with Strings, this is the standard function to convert.  You could make a loop to convert each character in the string returned by c_str() and then use then in checking if there is a match.

Suerte!

Laminamia :)
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:milalik
Comment Utility
How can I do that? can you post the code for that??

Gracias!
0
 

Author Comment

by:milalik
Comment Utility
Can someone explain me how can I use this in my program?

std::transform(townName.begin(), townName.end(), townName.begin(), ::tolower);
0
 

Author Comment

by:milalik
Comment Utility
How about changing just the first letter of a string to uppercase?
0
 
LVL 14

Accepted Solution

by:
AlexVirochovsky earned 50 total points
Comment Utility
For convert to low you have 2 options:
  townName=strlwr((char *)townName.c_str()); //or
  std::transform(townName.begin(),townName.end(),
               townName.begin(),::tolower);

To convert only 1-st letter to UP:
  std::transform(townName.begin(),townName.begin()+1,
               townName.begin(),::toupper);
  cout<< townName.c_str();

Tested with BC 5.01
Alex
0
 

Author Comment

by:milalik
Comment Utility
thanx
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now