|
-
February 17th, 2012, 09:09 PM
#1
[RESOLVED] Capitalize a String in C++
I have a problem. I need to print the string called "last" in uppercase format. can you check why my program prints nothing.
here is the important section of the code.
if (infile.is_open()) // if file was able to open
{
string line;
while (getline(infile, line))
{
string::size_type pos1 = line.find(' '); //pos1 is the position of the first space
if (pos1 != string::npos)
{
++pos1;
string::size_type pos2 = line.find(',', pos1); //pos2 is the position of the comma
string last = line.substr(pos1, pos2 - pos1); //remove everything before the first space
}
const int length = last.length();
for(int i=0; i!=length ; ++i)
{
last[i] = std::toupper(last[i]);
}
cout <<last <<endl;
outfile << last << endl;
infile.close();
outfile.close();
}
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|