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....

Recommended Answers

All 3 Replies

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.

>>while ('q' != getline(cin, str))

getline() doesn't return a character; it returns the this pointer.

got it to work, ty :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.