Solved

String

Posted on 2000-05-05
9
267 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
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 user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

786 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