Results 1 to 4 of 4

Thread: I am facing a problem please help me !

  1. #1
    Join Date
    Feb 2009
    Posts
    189
    Thanks
    2

    Unhappy I am facing a problem please help me !

    Dear Friends

    I am reading an int and a double from file.
    How can I check whetheer the value read is an int or double.


    int intval;
    double doubleval;
    ifstream infile("Data.dat")
    infile >> intval >> doubleval;

    // how can I check whether intval has got an integer and doubleval has got a double value.
    //infile.dat has
    2 23.323

    what happens if infile.dat has data like this

    # &&*********

    //so it'll read junk values so how could I check the variables.??

    Please help me to overcome this problem!!!

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: I am facing a problem please help me !

    not quite Qt related, right...?

    anyway, you should be able to use the fail() function on the stream.
    Qt Code:
    1. int anInt;
    2. astream >> anInt;
    3. if (astream.fail()) cerr << "not an int"
    To copy to clipboard, switch view to plain text mode 
    of course you have to take care that a float will usually also be accepted as an int, so if you tolerate either, try the float first.

  3. #3
    Join Date
    Sep 2009
    Location
    Guangzhou, China
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: I am facing a problem please help me !

    Anyway, if the file is designed yourself or your team, you should know the format of the file.

  4. #4
    Join Date
    Sep 2007
    Location
    Sant'Elpidio a Mare, Italy
    Posts
    194
    Thanks
    54
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: I am facing a problem please help me !

    If the file is made by you, you could constraint data in binary records to retrieve as structs.
    --
    raccoon29

    "La mia vita finirà quando non vedrò più la gente ridere...non necessariamente alle mie battute "

Similar Threads

  1. problem with opengl, zooming, drawpixels, and origin
    By ntp in forum General Programming
    Replies: 0
    Last Post: 22nd February 2008, 21:48
  2. Tricky problem with ARGB widget / UpdateLayeredWindow
    By nooky59 in forum Qt Programming
    Replies: 3
    Last Post: 21st February 2008, 10:35
  3. Graphics view display problem.
    By kiranraj in forum Qt Programming
    Replies: 3
    Last Post: 20th July 2007, 07:08
  4. [QMYSQL] connection problem
    By chaos_theory in forum Installation and Deployment
    Replies: 5
    Last Post: 2nd July 2007, 09:52
  5. Still facing Alignment problem in QTable
    By joseph in forum Qt Programming
    Replies: 5
    Last Post: 15th December 2006, 12:40

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.