error C276

Posted on 2005-04-30
Last Modified: 2009-12-16
Hello I am trying to make a program for my class and I am trying to make a sentinal value for one of my while loops but for the second condition that looks for the character "q". But I am getting an error:

error C2676: binary '!=' : 'std::string' does not define this operator or a conversion to a type acceptable to the predefined operator

Here is the code if it helps:

// This demonstrates a reasonable way to process a file until end-of-file
// Author: Colin Goble
// Inclass demo 4/28/2005

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>

using namespace std;

int main ()
      string fName, lName;
      char modality, grade;
      string line;
      ifstream inFile;
      string fileName;

      cout << "Please enter the input file name: ";
      cin >> fileName;;
      while ( ! inFile.is_open() || fileName != 'q') { // !!!!THIS IS THE LINE IN QUESTION!!!!
            cout << "File not found" << endl;
            cout << "Please try again: ";
            cin >> fileName;
      while ( inFile >> fName >> lName >> modality >> grade ) {
            cout << fName << " " << lName << " " << modality << " " << grade << endl;
      return 0;

Thank you for your Help!!!

Question by:Calv1n
    LVL 2

    Accepted Solution

    I am unfamiliar with this string class, and I could not find any documentation about it in the MSDN, but from what I saw in the headers, it has a function called "compare" which sounds like what you are looking for.
    You might need to assign 'q' to another instance of a string class and then pass it to the compare function.

    Also, you can always declare fileName as char*, allocate some memory useing malloc or calloc, and then use the standard strcmp function to compare it to 'q'.

    Hope this helps...
    LVL 9

    Expert Comment

    'q' is a character.
    "q" is a string.

    You can compare fileName with "q" or you can compare fileName[0] with 'q'.

    LVL 10

    Expert Comment


    // either you are comparing the whole of the filename, in which case you want to use != !q!

     while ( ! inFile.is_open() || fileName != "q")

    // or you are comparing the first character, in which case

     while ( ! inFile.is_open() || != 'q')

    the above assumes the filename is greater than 0 characters - if this is not true using at will throw an out of range exception, therefore i would do something like

     while ( ! inFile.is_open() || (fileName.length() > 0 && != 'q'))  

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Suggested Solutions

    Title # Comments Views Activity
    isEverywhere  challenge 19 48
    ImportError: No module named 'pypyodbc' - python 3.5.2 3 245
    mergeTwo  challenge 13 53
    noX challenge 17 52
    RIA (Rich Internet Application) tools are interactive internet applications which have many of the characteristics of desktop applications. The RIA tools typically deliver output either by the way of a site-specific browser or via browser plug-in. T…
    This is about my first experience with programming Arduino.
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now