Solved

String

Posted on 2000-05-05
9
259 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
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…
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.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

867 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

19 Experts available now in Live!

Get 1:1 Help Now