parsing in c++

This is a discussion on parsing in c++ within the C++ Programming forums, part of the General Programming Boards category; Code: // reading a text file #include <iostream> #include <fstream> #include <string> using namespace std; int main () { string ...

  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
    23,820
    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-06-2008, 11:55 PM
  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, 04:31 PM
  4. Need help fixing bugs in data parsing program
    By daluu in forum C Programming
    Replies: 8
    Last Post: 03-27-2003, 05: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, 06:30 PM

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