0

I am having a similar issue

// Exc_3.cpp - Testing string with refernece

#include <iostream>
#include <cctype>
#include <string>
#include <cstring>

using namespace std;

string lowerToUpper(string & ref);

int main()
{
	string str;
	string constant = "q";
	cout << "Enter a string (q to quit): ";
	//while (constant != getline(cin, str))
	while ('q' != getline(cin, str))
	//while (!strcmp(constant, getline(cin,str)))
	{
		str = lowerToUpper(str);
		cout << str << endl;
		cout << "Enter a string (q to quit): ";
	}
}

string lowerToUpper(string & ref)
{
	for(int i = 0; i < ref.size(); i++)
	{
		string[i] = toupper(string[i]);
	}
}

I have tried 3 different ways, and can't get them to work. Kinda confused on your explantion....

3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by MasterGberry
0

Get rid of the 'q' != part and test whether str is equal to q before line 21. If it is, break out of the loop. That's probably the most straightforward way to to do it.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.