instead of making a new topic i decided to just edit a old one. What i need to do is take the first letter of each string read from a input file and upper case it
ex:
start: i sparkle when i go out into the sun.
after: I sparkle when i go out into the sun.
I have the input/output done just need a little help with the function to convert the first object in the string.
I found this code, would using it to the trick?Code:#include <iostream> #include <fstream> using namespace std; void initialCap(&string); { } int main() { string line; ifstream input ("input.txt"); ofstream outfile ("output.txt"); if (input.is_open()) { while (!input.eof()) { getline (input,line); cout << line << endl; outfile << line << endl; } input.close(); } else cout << "This file does not exist"; return 0; }
Code:string initialCap(string str) { string::iterator it(str.begin()); if (it != str.end()) str[0] = toupper((unsigned char)str[0]); while(++it != str.end()) { *it = tolower((unsigned char)*it); } return str; }
XI Wiki





