Problem : setw' undeclared ?



  • Hi,

    wie kann ich folgenden Fehler beheben ?

    [cpp]h3827:~/rayt_installs # g++ -o test1 -I/usr/include/mysql -I/usr/include/sqlplus test1.cc
    In file included from /usr/include/g++/backward/iterator.h:30,
    from /usr/include/sqlplus/resiter1.hh:6,
    from /usr/include/sqlplus/row1.hh:10,
    from /usr/include/sqlplus/compare1.hh:6,
    from /usr/include/sqlplus/sqlplus.hh:13,
    from test1.cc:3:
    test1.cc: In function int main()': **test1.cc:33:setw' undeclared (first use this function)**
    test1.cc:33: (Each undeclared identifier is reported only once for each
    function it appears in.)
    [/cpp]

    Sample Code :

    #include <sstream>
    #include <iomanip>
    #include </usr/include/sqlplus/sqlplus.hh>
    
    int main() 
    {
       // The full format for the Connection constructor is
      // Connection(cchar *db, cchar *host="", 
      //            cchar *user="", cchar *passwd="") 
      // You may need to specify some of them if the database is not on
      // the local machine or you database username is not the same as your
      // login name, etc..
      try {
    		Connection con("mysql_cpp_data");
    		Query query = con.query();
    		// This creates a query object that is bound to con.
    
    		query << "select * from stock";
    		// You can write to the query object like you would any other ostrem
    
    		Result res = query.store();
    		// Query::store() executes the query and returns the results
    
    		cout << "Query: " << query.preview() << endl;
    		// Query::preview() simply returns a string with the current query
    		// string in it.
    
    		cout << "Records Found: " << res.size() << endl << endl;
    
    		Row row;
    		cout.setf(ios::left);
    		cout << std::setw(17) << "Item" 
    			<< setw(4)  << "Num"
    			<< setw(7)  << "Weight"
    			<< setw(7)  << "Price" 
    			<< "Date" << endl
    			<< endl;
    
    		Result::iterator i;
    		// The Result class has a read-only Random Access Iterator
    		for (i = res.begin(); i != res.end(); i++) {
    			row = *i;
    			cout << setw(17) << row[0].c_str()
    				<< setw(4)  << row[1].c_str()
    				<< setw(7)  << row["weight"].c_str()
    				// you can use either the index number or column name when
    				// retrieving the colume data as demonstrated above.
    				<< setw(7)  << row[3].c_str()
    				<< row[4] << endl;
    		}
      } catch (BadQuery &er) { // handle any connection or
                              // query errors that may come up
    #ifdef USE_STANDARD_EXCEPTION
        cerr << "Error: " << er.what() << endl;
    #else
        cerr << "Error: " << er.error << endl;
    #endif
        return -1;
      } catch (BadConversion &er) { // handle bad conversions
    #ifdef USE_STANDARD_EXCEPTION
        cerr << "Error: " << er.what() << "\"." << endl
             << "retrieved data size: " << er.retrieved
             << " actual data size: " << er.actual_size << endl;
    #else
        cerr << "Error: Tried to convert \"" << er.data << "\" to a \""
             << er.type_name << "\"." << endl;
    #endif
        return -1;
    #ifdef USE_STANDARD_EXCEPTION		
      } catch (exception &er) {
        cerr << "Error: " << er.what() << endl;
        return -1;
    #endif		
      }
    	return 0;
    }
    

    Ich benutz folgenden Compiler : gcc (GCC) 3.2

    Danke im Vorraus,

    Proteus



  • cout << std::setw(17) << "Item"  << setw(4)  << "Num"
    

    Warum nur einmal das std:: ? Ich denke mal es liegt daran, wenns dir zu anstrengend ist, das jedesmal zu schreiben, dann mach doch using std::setw;


Anmelden zum Antworten