Thread: parsing in c++

  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    35

    parsing in c++

    Code:
    // reading a text file
    #include <iostream>
    #include <fstream>
    #include <string>
    using namespace std;
    
    int main () {
      string line;
      ifstream myfile ("example1.txt");
      ofstream myargument ("putonqueue.txt",ios::out | ios::app);
      if (myfile.is_open())
      {
        while (! myfile.eof() )
        {
    	 // expects either space-delimited numbers 
        
        
        while( getline(myfile,line) ) {
         
            istringstream ss (line);
            double d;
            while( ss >> d ) {
              cout << "  got a number: " << d << endl;
            }
          }
     }
        myfile.close();
        myargument.close();
      }
    
      else cout << "Unable to open file"; 
    
      return 0;
    }
    Hi I am trying to parse a text file in c++.The above code gives a compiler error:
    argque.cpp: In function `int main()':
    argque.cpp:20: error: variable `std::istringstream ss' has initializer but incomplete type

    what does it mean?
    any help or insight is appreciated.
    Thanks
    shweta

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You forgot to #include <sstream>.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need sth about parsing
    By Masterx in forum C++ Programming
    Replies: 6
    Last Post: 11-07-2008, 12:55 AM
  2. draw tree graph of yacc parsing
    By talz13 in forum C Programming
    Replies: 2
    Last Post: 07-23-2006, 01:33 AM
  3. Parsing for Dummies
    By MisterWonderful in forum C++ Programming
    Replies: 4
    Last Post: 03-08-2004, 05:31 PM
  4. Need help fixing bugs in data parsing program
    By daluu in forum C Programming
    Replies: 8
    Last Post: 03-27-2003, 06:02 PM
  5. I hate string parsing with a passion
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 03-19-2002, 07:30 PM