我只需要一些调试帮助(C ++)。我遇到了多个问题,我不确定如何修复

时间:2015-04-06 19:10:31

标签: c++ debugging

如果你们可以帮忙修改我的代码,我将永远感激。

这些是Visual Studio 2013不断向我发布的错误。

1>------ Build started: Project: PA2, Configuration: Debug Win32 ------

1>  Main.cpp

1>filepath(71): error C2146: syntax error : missing ')' before identifier 'i'

1>filepath(71): error C2061: syntax error : identifier 'i'

1>filepath(71): error C2059: syntax error : ')'

1>filepath(73): error C2143: syntax error : missing '}' before ';'

1>filepath(73): error C2064: term does not evaluate to a function taking 1 
arguments

1>filepath(74): error C2146: syntax error : missing ';' before identifier 'endl'

1>filepath(74): warning C4551: function call missing argument list

1>filepath(75): error C2676: binary '[' : 'std::ofstream' does not define this 
operator or a conversion to a type acceptable to the predefined operator

1>filepath(75): error C2228: left of '.ISBN' must have class/struct/union

1>filepath(77): error C2676: binary '[' : 'std::ofstream' does not define this 
operator or a conversion to a type acceptable to the predefined operator

1>filepath(77): error C2228: left of '.Author' must have class/struct/union

1>filepath(79): error C2676: binary '[' : 'std::ofstream' does not define this 
operator or a conversion to a type acceptable to the predefined operator
1>filepath(79): error C2228: left of '.Title' must have class/struct/union

1>filepath(81): error C2676: binary '[' : 'std::ofstream' does not define this 
operator or a conversion to a type acceptable to the predefined operator

1>filepath(81): error C2228: left of '.Quantity' must have class/struct/union

1>filepath(83): error C2676: binary '[' : 'std::ofstream' does not define this 
operator or a conversion to a type acceptable to the predefined operator

1>filepath(83): error C2228: left of '.Price' must have class/struct/union

1>filepath(84): warning C4804: '>' : unsafe use of type 'bool' in operation

1>filepath(92): error C2046: illegal case

1>filepath(97): error C2059: syntax error : ';'

1>filepath(98): error C2440: '=' : cannot convert from 'nullptr' to 'int'

1>          A native nullptr can only be converted to bool or, using 
reinterpret_cast, to an integral type

1>filepath(101): error C2046: illegal case

1>filepath(129): error C2676: binary '[' : 'std::ofstream' does not define this 
operator or a conversion to a type acceptable to the predefined operator

1>filepath(129): error C2228: left of '.ISBN' must have class/struct/union

1>filepath(131): error C2676: binary '[' : 'std::ofstream' does not define this 
operator or a conversion to a type acceptable to the predefined operator

1>filepath(131): error C2228: left of '.Quantity' must have class/struct/union

1>filepath(137): error C2676: binary '[' : 'std::ofstream' does not define this 
operator or a conversion to a type acceptable to the predefined operator

1>filepath(139): error C2676: binary '[' : 'std::ofstream' does not define this 
operator or a conversion to a type acceptable to the predefined operator

1>filepath(139): error C2228: left of '.Quantity' must have class/struct/union

1>filepath(145): error C2676: binary '[' : 'std::ofstream' does not define this 
operator or a conversion to a type acceptable to the predefined operator

1>filepath(148): error C2676: binary '[' : 'std::ofstream' does not define this 
operator or a conversion to a type acceptable to the predefined operator

1>filepath(148): error C2228: left of '.Quantity' must have class/struct/union

1>filepath(149): error C2676: binary '[' : 'std::ofstream' does not define this 
operator or a conversion to a type acceptable to the predefined operator

1>filepath(149): error C2228: left of '.Quantity' must have class/struct/union

1>filepath(160): error C2143: syntax error : missing ';' before '{'

1>filepath(166): error C2046: illegal case

1>filepath(175): error C2143: syntax error : missing ';' before 'do'

1>filepath(179): error C2146: syntax error : missing ';' before identifier 
'binarySearch'

1>filepath(179): error C3861: 'binarySearch': identifier not found

1>filepath(182): error C2143: syntax error : missing ';' before '{'

1>filepath(188): error C2046: illegal case

1>          c:\program files (x86)\microsoft visual studio 
12.0\vc\include\string(135) : see declaration of 'std::operator >>'

1>          c:\program files (x86)\microsoft visual studio 
12.0\vc\include\string(135) : see declaration of 'std::operator >>'

1>          c:\program files (x86)\microsoft visual studio 
12.0\vc\include\string(135) : see declaration of 'std::operator >>'

1>          c:\program files (x86)\microsoft visual studio 
12.0\vc\include\string(135) : see declaration of 'std::operator >>'

1>          c:\program files (x86)\microsoft visual studio 
12.0\vc\include\string(135) : see declaration of 'std::operator >>'

1>          c:\program files (x86)\microsoft visual studio 
12.0\vc\include\string(21) : see declaration of 'std::operator >>'

1>          c:\program files (x86)\microsoft visual studio 
12.0\vc\include\string(21) : see declaration of 'std::operator >>'

1>          c:\program files (x86)\microsoft visual studio 
12.0\vc\include\string(21) : see declaration of 'std::operator >>'

1>          c:\program files (x86)\microsoft visual studio 
12.0\vc\include\string(21) : see declaration of 'std::operator >>'

1>          c:\program files (x86)\microsoft visual studio 
12.0\vc\include\string(21) : see declaration of 'std::operator >>'

1>          c:\program files (x86)\microsoft visual studio 
12.0\vc\include\istream(1103) : see declaration of 'std::operator >>'

1>          c:\program files (x86)\microsoft visual studio 
12.0\vc\include\istream(1103) : see declaration of 'std::operator >>'

1>          c:\program files (x86)\microsoft visual studio 
12.0\vc\include\istream(1103) : see declaration of 'std::operator >>'

1>          c:\program files (x86)\microsoft visual studio 
12.0\vc\include\istream(1103) : see declaration of 'std::operator >>'

1>          c:\program files (x86)\microsoft visual studio 
12.0\vc\include\istream(1103) : see declaration of 'std::operator >>'

1>          c:\program files (x86)\microsoft visual studio 
12.0\vc\include\istream(1093) : see declaration of 'std::operator >>'

1>          c:\program files (x86)\microsoft visual studio 
12.0\vc\include\istream(1093) : see declaration of 'std::operator >>'

1>          c:\program files (x86)\microsoft visual studio 
12.0\vc\include\istream(1093) : see declaration of 'std::operator >>'

1>          c:\program files (x86)\microsoft visual studio 
12.0\vc\include\istream(1093) : see declaration of 'std::operator >>'

1>          c:\program files (x86)\microsoft visual studio 
12.0\vc\include\istream(1093) : see declaration of 'std::operator >>'

1>          c:\program files (x86)\microsoft visual studio 
12.0\vc\include\istream(1086) : see declaration of 'std::operator >>'

1>          c:\program files (x86)\microsoft visual studio 
12.0\vc\include\istream(1086) : see declaration of 'std::operator >>'

1>          c:\program files (x86)\microsoft visual studio 
12.0\vc\include\istream(1086) : see declaration of 'std::operator >>'

1>          c:\program files (x86)\microsoft visual studio 
12.0\vc\include\istream(1086) : see declaration of 'std::operator >>'

1>          c:\program files (x86)\microsoft visual studio 
12.0\vc\include\istream(1086) : see declaration of 'std::operator >>'

1>          c:\program files (x86)\microsoft visual studio 
12.0\vc\include\istream(1079) : see declaration of 'std::operator >>'

1>          c:\program files (x86)\microsoft visual studio 
12.0\vc\include\istream(1079) : see declaration of 'std::operator >>'

1>          c:\program files (x86)\microsoft visual studio 
12.0\vc\include\istream(1079) : see declaration of 'std::operator >>'

1>          c:\program files (x86)\microsoft visual studio 
12.0\vc\include\istream(1079) : see declaration of 'std::operator >>'

1>          c:\program files (x86)\microsoft visual studio 
12.0\vc\include\istream(1079) : see declaration of 'std::operator >>'

1>          c:\program files (x86)\microsoft visual studio 
12.0\vc\include\istream(1072) : see declaration of 'std::operator >>'

1>          c:\program files (x86)\microsoft visual studio 
12.0\vc\include\istream(1072) : see declaration of 'std::operator >>'

1>          c:\program files (x86)\microsoft visual studio 
12.0\vc\include\istream(1072) : see declaration of 'std::operator >>'

1>          c:\program files (x86)\microsoft visual studio 
12.0\vc\include\istream(1072) : see declaration of 'std::operator >>'

1>          c:\program files (x86)\microsoft visual studio 
12.0\vc\include\istream(1072) : see declaration of 'std::operator >>'

1>          c:\program files (x86)\microsoft visual studio 
12.0\vc\include\istream(1047) : see declaration of 'std::operator >>'

1>          c:\program files (x86)\microsoft visual studio 
12.0\vc\include\istream(1047) : see declaration of 'std::operator >>'

1>          c:\program files (x86)\microsoft visual studio 
12.0\vc\include\istream(1047) : see declaration of 'std::operator >>'

1>          c:\program files (x86)\microsoft visual studio 
12.0\vc\include\istream(1047) : see declaration of 'std::operator >>'

1>          c:\program files (x86)\microsoft visual studio 
12.0\vc\include\istream(1047) : see declaration of 'std::operator >>'

1>          c:\program files (x86)\microsoft visual studio 
12.0\vc\include\istream(1006) : see declaration of 'std::operator >>'

1>          c:\program files (x86)\microsoft visual studio 
12.0\vc\include\istream(1006) : see declaration of 'std::operator >>'

1>          c:\program files (x86)\microsoft visual studio 
12.0\vc\include\istream(1006) : see declaration of 'std::operator >>'

1>          c:\program files (x86)\microsoft visual studio 
12.0\vc\include\istream(1006) : see declaration of 'std::operator >>'

1>          c:\program files (x86)\microsoft visual studio 
12.0\vc\include\istream(1006) : see declaration of 'std::operator >>'

1>filepath(198): error C2047: illegal default

1>filepath(203): error C2059: syntax error : ';'

1>filepath(205): error C2059: syntax error : 'while'

1>filepath(208): error C2447: '{' : missing function header (old-style formal 
list?)

1>filepath(216): error C4430: missing type specifier - int assumed. Note: C++ 
does not support default-int

1>filepath(216): error C2365: 'system' : redefinition; previous definition was 
'function'

1>          c:\program files (x86)\microsoft visual studio 
12.0\vc\include\stdlib.h(560) : see declaration of 'system'

1>filepath(216): error C2440: 'initializing' : cannot convert from 'const char 
[6]' to 'int'

1>          There is no context in which this conversion is possible

1>filepath(217): error C2059: syntax error : 'return'

1>filepath(218): error C2059: syntax error : '}'

1>filepath(218): error C2143: syntax error : missing ';' before '}'

========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

//This program is to keep track of book entries at a book store 
#include <iostream>
#include <string>
#include <stdlib.h>
#include <fstream>
using namespace std;
int main()
{
string NAME;
char var;
string booklist[100];
string output;

var = '1';  //These are the usuable variables
var = '2';
var = '3';
var = '4';
var = '5';
var = '6';


cout << "What is your name?" << endl;   //This wasn't necessary but I felt that asking for your name made it more friendly. 
getline(cin, NAME, '\n');

cout << "Welcome " << NAME << ", I hope this program greately benefits you! \n" << endl;

struct bookList //Structure for all arrays 
{
    int ISBN;       //Book ISBN number
    string Author;  //Book Author
    string Title;   //Book Title
    int Quantity;   //Book Quantity
    double Price;   //Book Price
};

// do loop execution
do
{
    cout << "Please select an operation: \n \n \n";
    cout << "1: Read inventory from file \n \n";
    cout << "2: Add an entry \n \n";
    cout << "3: Delete an entry \n \n";
    cout << "4: Update an entry \n \n";
    cout << "5: Sort inventory \n \n";
    cout << "6: Write inventory to file and exit \n \n";
    cin >> var;
    switch (var)
    {
    case 1:
    {   //Case 1 will read the inventory from inventory.dat
        ofstream bookList;
        bookList.open("inventory.dat");
        void printArray();
        cout << endl;
        bookList.close();
    }
    break;
    case 2:
    {   //Case 2 asks for infomation from the user to store into the array. It then sorts the information and also checks if the array is full. 
        int i;
        int ISBN;
        string Author;
        string Title;
        int Quantity;
        double Price;
        double MAX_SIZE = 100;
        ofstream bookList;

        do (int i = 0; i < MAX_SIZE; i++)
        {
            cout << "Here you can add a book to the database.\n\n" << endl;
            cout << "Please enter the ISBN number.\n" endl;
            cin >> bookList[i].ISBN << endl;
            cout << "Please enter the name of the Author\n";
            cin >> bookList[i].Author << endl;
            cout << "Please enter the name of the title\n";
            cin >> bookList[i].Title << endl;
            cout << "Please enter the Quantity\n";
            cin >> bookList[i].Quantity << endl;
            cout << "Please enter the Price of the book\n";
            cin >> bookList[i].Price << endl;
            while (i > !MAX_SIZE)
            {
                cout << "Error: There is no more room to add entries. You will now be returned to the main menu." << endl;
            }
        };
        return 0;
    }
    break;
    case 3:
    {   //3 deletes an entry by moving the other entries below the selected one and then decreases the array size by one.
        int number;
        cout << "You are about to delete an entry.\n\n" << "Please enter the number of the entry you'd like to remove.\n";
        cin >> number;
        delete[number];
        number = nullptr;
    }
    break;
    case 4:
    {   //4 is updating the quantitiy of an entry in the array.
        int i;
        char var;
        int ISBN;
        string Author;
        string Title;
        int Quantity;
        double Price;
        ofstream bookList;

        var = 0;
        var = 1;
        var = 2;
        var = 3;

        cout << "Here you can update the Quantity of a book that you have stored in the database.\n\n" << "Please enter the ISBN number of the entry you'd like to update.\n";
        cin >> i;
        cout << "Would you like to increase, decrease, or type the Quantity?\n\n" << "Type :\n" << "     1 to increase the value by one.\n";
        cout << "     2 to decrease the value by one.\n" << "     3 to enter a new value.\n" << "     0 to return to the main menu\n";
        cin >> var;

        do
        {
            switch (var)
            {
            case 1:
            {   //1 will increase the value by one.
                if (bookList[i].ISBN == i)
                {
                    bookList[i].Quantity++ << endl;
                }
            }
            break;
            case 2:
            {   //2 will decrease the value by one.
                if (bookList[ISBN] == i)
                {
                    bookList[i].Quantity-- << endl;
                }
            }
            break;
            case 3:
            {   //3 will allow you to enter an entirely new number.
                if (bookList[ISBN] == i)
                {
                    cout << "You currently have " << Quantity << " .\n" << "Please enter the updated Quantity\n";
                    cin >> bookList[i].Quantity << endl;
                    cout << "Your new Quantity is " << bookList[i].Quantity << ".\n" << endl;
                }
            }
            break;
            default:
            {
                cout << "Please enter a number between 1 and 3.\n";
            }
            break;
            }
        } while (var != 0)
        {
            return 0;
        }

    }
    break;
    case 5:
    {   //Case 5 is to just sort the array by title
        int ISBN;
        string Author;
        string Title;
        int Quantity;
        double Price;
        int input 

        do
        {
            cout << "To search by title, press 1.\n";
            cin >> input
            binarySearch(Title);
            cout << "The database is now sorted by title.";
        } while (input != 0)
        {
            return 0;
        }

    }
    break;
    case 6:
    {   //Case 6 outputs text and exits the program.
        ofstream bookList;
        bookList.open("inventory.dat");
        bookList >> output;
        cout << output;
        bookList.close();
        exit(0);
    }
    break;
    default:
    {
        cout << "Please enter a number between 1 and 6.\n";
    }
    break;
    };

} while (var != 6);

void printArray(int arr[], int size);
{
    for (int i = 0; i < MAX_SIZE; i++)
    {
        cout << bookList[i] << ' ';
    }
    cout << endl;
}

system("pause");
return 0;}

1 个答案:

答案 0 :(得分:1)

这里有一些免费赠送的代码可以帮助您入门:

book.hpp:

class Book 
{
  public:  
    // empty or default constructor.
    Book()
    { }

    // A constructor
    Book(const std::string& new_title,
         const std::string& new_author,
         const std::string& new_isbn,
         double new_price)
    : Title(new_title),
      Author(new_author),
      ISBN(new_isbn),
      Price(new_price)
   { }

  void input_from_user(void);

  friend std::ostream& operator<<(std::ostream& out, const Book& b);


  private:
    string ISBN;       //Book ISBN number
    string Author;  //Book Author
    string Title;   //Book Title
    double Price;   //Book Price
};

<强> book.cpp:

ostream&  operator<<(ostream& out, const Book& b)
{
  out << b.Title << ","
      << b.Author << ","
      << b.ISBN << ","
      << b.Price << "\n";
}

void
Book :: 
input_from_user(void)
{
  cout << "Enter book title:\n";
  getline(cin, Title);
  cout << "Enter book author:\n";
  getline(cin, Author);
  cout << "Enter ISBN:\n";
  getline(cin, ISBN);
  cout << "Enter price: ";
  cin >> Price;
}

<强> main.cpp中:

#include "book.hpp"

int main(void)
{
  Book b;
  b.input_from_user();
  cout << "\nThe book data, in CSV format:\n";
  cout << b;
  return EXIT_SUCCESS;
}