Solved

String

Posted on 2000-05-05
9
274 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
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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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 50 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

792 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