?
Solved

String

Posted on 2000-05-05
9
Medium Priority
?
288 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 2
9 Comments
 
LVL 3

Expert Comment

by:Laminamia063099
ID: 2782121
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
ID: 2782158
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
ID: 2782260
Need help converting the string in all lowercase
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:Laminamia063099
ID: 2782262
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
 

Author Comment

by:milalik
ID: 2782334
How can I do that? can you post the code for that??

Gracias!
0
 

Author Comment

by:milalik
ID: 2783002
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
ID: 2783007
How about changing just the first letter of a string to uppercase?
0
 
LVL 14

Accepted Solution

by:
AlexVirochovsky earned 150 total points
ID: 2783738
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
ID: 2783955
thanx
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses
Course of the Month12 days, 15 hours left to enroll

777 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