Use of size() in c++ -
This is the program I want to change "A" from "A" But when I pass a string of more than one word (example: very good) it only takes the first word
I understand the use of the replacement (), but I want to try something from scratch I am very new in this
#include & lt; Iostream & gt; #include & lt; String & gt; using namespace std; String asesToUpperCase (string word) {for (int i = 0; i & lt; word.size (;; i ++) if (word [i] == 'a') word [i] = 'a'; Return word; } Int main () {string aword; Cout & lt; & Lt; "Enter a word:"; Cin & gt; & Gt; One word; Cout & lt; & Lt; AsesToUpperCase (aword); Return 0; }
I think the problem is that you have the operator & gt; & Gt; Use the standard function std :: getline instead of entering several words in a string. Keep in mind that standard algorithm std :: replace which works. For example
#include & lt; Algorithm & gt; // ... std :: Change (word.begin (), word.end (), 'A', 'A');
Comments
Post a Comment