-2

I want the code to search for a word mid sentence and see if its first letter is lower case.

If it is, than it makes it upper case. For example: John hates using c++ daily, and it would change the C in c++ to uppercase.

Here is the code

#include <iostream>
#include <string>
#include<cstdlib>
#include<fstream>
using namespace std;

ifstream in_stream;
ofstream out_stream;

int main()
{
    in_stream.open("in.dat");
    out_stream.open("out.dat");
    char s[256];
    in_stream>>s;
    s[0] = tolower(s[0]);
    out_stream<<s;

    in_stream.close();
    out_stream.close();
    system("Pause");
    return 0;
}
QuestionC
  • 10,006
  • 4
  • 26
  • 44
user3694341
  • 11
  • 1
  • 5

1 Answers1

1

Redefine s to be of type std::string

std::string wordOfInterest = "c++" // Change as per your needs
std::string::size_type pos = s.find(wordOfInterest); // Index at which the word of interest starts
if (pos != std::string::npos) s[pos] = toupper(s[pos]); // Updating the value at index with its upper case counterpart
The Vivandiere
  • 3,059
  • 3
  • 28
  • 50