Like Tree1Likes

syntax error : 'bad suffix on number'

This is a discussion on syntax error : 'bad suffix on number' within the C++ Programming forums, part of the General Programming Boards category; Code: #include <iostream> #include <string> #include <fstream> #include <iomanip> using namespace std; const int Max=100; struct Item { string ID; ...

  1. #1
    Registered User
    Join Date
    Dec 2012
    Posts
    23

    Exclamation syntax error : 'bad suffix on number'

    Code:
    #include <iostream>
    #include <string> 
    #include <fstream>
    
    #include <iomanip>
    
    using namespace std;
    
    const int Max=100;
    
    struct Item
    
    {
    
    string ID;
    
    int sold;
    
    int rem;
    
    };
    
    void read(Item Itemlist[], int length, string filename)
    
    {
    
    std::ifstream infile("filename.txt");
    
    std::ofstream outfile("filename.txt");
    
    infile.open("filename");
    
    for(int i=0; i<length; i++)
    
    {
    
    infile >> Itemlist[i].ID;
    
    cin.ignore(100, ' ');
    
    infile >> Itemlist[i].sold;
    
    cin.ignore(100, ' ');
    
    infile >> Itemlist[i].rem;
    
    }
    
    return;
    
    }

    I get this error for every line of code in my text file. i figure the problem must be here.


    This is a piece of what i have in main

    Code:
    #include "C:\Users\User\Desktop/inventory.txt"
    #include "myfile.h"
    #include <iostream>
    #include <string>
    #include <fstream>
    #include <iomanip>
    using namespace std;
    
    
    int main()
    {
         struct Item myArray[Max];
    
    
        read(myArray, Max, "inventory.txt");
    ..etc
    Last edited by val3ri3; 12-06-2012 at 04:31 AM.

  2. #2
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    You are missing a : here
    Code:
    std:ofstream outfile("filename.txt");
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  3. #3
    Registered User
    Join Date
    Dec 2012
    Posts
    23
    yea woah actually i accidentaly erased it when i copied the code on here but its on my code let me fix that

  4. #4
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Ok. You located the error. It has to do with the struct! You do not have anything named Item, you have only something named struct Item, so you need to write
    Code:
    struct Item myArray[Max];
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  5. #5
    Registered User
    Join Date
    Dec 2012
    Posts
    23
    In my main?

  6. #6
    Registered User
    Join Date
    Dec 2012
    Posts
    23
    Please Look On my code.. Is that what you meant for me to do?

  7. #7
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Yes

    A good tip could be not to edit every time the first post, because this is opposite from the flow of the post.

    Also I would suggest you to indent your code a bit



    Finally, welcome to the forum
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  8. #8
    Registered User
    Join Date
    Dec 2012
    Posts
    23
    Ah sorry haha
    and Thanks so much
    Problem is im still getting the error i think it's my read function

  9. #9
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Code:
    #include "C:\Users\User\Desktop/inventory.txt"
    You're including your data file as if it was program code. The compiler errors you get are when your poor abused compiler attempts to parse your data as C++.

    Apologize to your compiler and remove that line.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  10. #10
    Registered User
    Join Date
    Dec 2012
    Posts
    23
    Ok so this is what i have now in main
    Code:
    #include "inventory.txt"
    #include "myfile.h"
    #include <iostream>
    #include <string>
    #include <fstream>
    #include <iomanip>
    using namespace std;
    
    
    int main()
    {
        struct Item myArray[Max];
        read( myArray, Max, "inventory.txt");
    in my header file
    Code:
    #include <iostream>
    #include <string>
    #include <fstream>
    #include <iomanip>
    using namespace std;
    const int Max=100;
    struct Item
    {
        string ID;
        int sold;
        int rem;
    };
    void read(Item Itemlist[], int length, string filename)
    {
    
    
    
    
        std::ifstream infile("filename.txt");
        std::ofstream outfile("filename.txt");
        infile.open("filename");
        for(int i=0; i<length; i++)
        {
            infile >> Itemlist[i].ID;
            cin.ignore(100, ' ');
            infile >> Itemlist[i].sold;
            cin.ignore(100, ' ');
            infile >> Itemlist[i].rem;
        }
        return;
    }
    and my text file im trying to read from
    Code:
    619847GBE 641 998
    418712IMB 107 867
    227451GEM 789 181
    981836KEA 747 171
    986516IGU 303 71
    501024BMU 895 743
    455559SKK 764 234
    706756EUU 687 730
    500635MIS 841 670
    341955IUS 32 907
    791357GEK 391 284
    etc




    Im getting this error for every line in my text file
    error C2059: syntax error : 'bad suffix on number'

  11. #11
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Code:
    void read(Item Itemlist[]
    YOu are missing again the struct
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  12. #12
    Registered User
    Join Date
    Dec 2012
    Posts
    23
    Code:
    void read(struct Item Itemlist[], string filename)
    {
    
    
    
    
    	std::ifstream infile("filename.txt");
        std::ofstream outfile("filename.txt");
    	infile.open("filename");
    	for(int i=0; i<Max; i++)
    	{
    		infile >> Itemlist[i].ID;
    		cin.ignore(100, ' ');
    		infile >> Itemlist[i].sold;
    		cin.ignore(100, ' ');
    		infile >> Itemlist[i].rem;
    	}
    	return;
    }

  13. #13
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    The line of code with return is not needed, but this not an error.

    Also the second parameter is really unused. Maybe you wanted to say filename instead of "filename"
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  14. #14
    Registered User
    Join Date
    Dec 2012
    Posts
    23
    Yes i fixed that my code looks cleaner, but im still getting my same error

  15. #15
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    What do you mean? Post here your updated code please.
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. xorq: Error: suffix or operands invalid for `xor'
    By Tsus86 in forum C Programming
    Replies: 2
    Last Post: 09-21-2011, 03:49 AM
  2. Replies: 0
    Last Post: 10-13-2010, 05:36 AM
  3. Overloaded Function/Bad Number Suffix
    By zerkz in forum C++ Programming
    Replies: 4
    Last Post: 04-19-2009, 01:37 PM
  4. Strange struct syntax; type name:number
    By OnionKnight in forum C Programming
    Replies: 1
    Last Post: 11-19-2006, 08:23 PM
  5. Replies: 2
    Last Post: 09-12-2006, 05:50 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21