February 17th, 2012, 09:09 PM
[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
while (getline(infile, line))
string::size_type pos1 = line.find(' '); //pos1 is the position of the first space
if (pos1 != string::npos)
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;
Tags for this Thread
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.