This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

expected unqualified-id before.....


Hello all,

I have a problem compiling a cpp wich seems to me correct, this is the error:

iniToXml.cpp:18: error: 'string' does not name a type
iniToXml.cpp:19: error: 'string' does not name a type
iniToXml.cpp:21: error: expected constructor, destructor, or type
conversion before '<' token
iniToXml.cpp:22: error: expected constructor, destructor, or type
conversion before '<' token
iniToXml.cpp:23: error: expected constructor, destructor, or type
conversion before '<' token
iniToXml.cpp:26: error: expected constructor, destructor, or type
conversion before '<' token
iniToXml.cpp:47: error: expected constructor, destructor, or type
conversion before '<' token
iniToXml.cpp:57: error: expected constructor, destructor, or type
conversion before '<' token
iniToXml.cpp:60: error: expected unqualified-id before 'for'
iniToXml.cpp:60: error: expected constructor, destructor, or type
conversion before '<' token
iniToXml.cpp:60: error: expected unqualified-id before '++' token
iniToXml.cpp:89: error: expected unqualified-id before 'do'
iniToXml.cpp:112: error: expected unqualified-id before 'while'
iniToXml.cpp:113: error: expected unqualified-id before 'return'
iniToXml.cpp:114: error: expected declaration before '}' token

What should i do?

Best regards

A. Mauro
#include <xercesc/dom/DOM.hpp>
#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/util/XMLString.hpp>
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <sstream>
#include <stdexcept>

XERCES_CPP_NAMESPACE_USE

//using namespace std;

struct Dati {
    int lvl;                //indica il livello gerarchia dei dai nel fileini
    int type;               //indica il tipo di nodo (element, text,comment...)
    string elemento;
    string valore;
};
vector<string> parse(FILE* ilfile);
vector<string> delSpaces(vector<string> file);
vector<Dati> solve(const vector<string> file);

//riceve in ingresso un * a FILE e ne copia il contenuto riga per riga in un vettore di stringhe
vector<string> parse(FILE* ilfile){
  vector<string> temp;
  string s;
  char c;
  do
  {
	s = "";
	//ciclo di scorrimento linea, necessario controllo EOF onde evitare loop infinito
    while (((c=getc(ilfile)) != '\n')&&(c!=EOF)){
		s.append(&c, 1);
    }
    if(s.length()!=0 && s.find_first_not_of(' ')!=string::npos && s!="\n"){  
//controllo che la riga non sia vuota
        temp.push_back(s); //funzione dei vector, pusha il elemento di s nella successiva cella di temp
    }
  }while (c!=EOF);
  temp=delSpaces(temp);
  return temp;
}

//Chiamata su un vettore di stringhe modifica il vettore stesso togliendo gli spazi iniziali e finali a ciascuna stringa
vector<string> delSpaces(vector<string> file){
  for(int i=0; i<file.size() ;++i){
    //Copia la dalla stringa in input una sottostringa che parte dal primo carattere "non space" all'ultimo carattere "non space"
    file.at(i)=file.at(i).substr(file.at(i).find_first_not_of(' '), 
file.at(i).find_last_not_of(' ') - file.at(i).find_first_not_of(' ') + 1);
  }
  return file;
}

//Copia ogni cella del vettore in ingresso in un nuovo vettore multidimensionale e stabilisce il tipo di ogni cella vector<Dati> solve(const vector<string> file){
   vector<Dati> tempVD;
   Dati tempDati;
   int levelCounter(0);
   for(int i=0; i<file.size() ;++i){
     //tempDati.elemento=file[i]; //"setto" la struct (elemento)
       if(file.at(i).substr(0,7)=="[inizio"){
       tempDati.elemento=file.at(i).substr(8,file.at(i).length()-9);
       tempDati.valore=file.at(i).substr(8,file.at(i).length()-9);
       tempDati.lvl=levelCounter; //"setto" la struct (lvl) corrispondente al livello gerarchico dell XML, root=0... child di root=1...
       tempDati.type=1; //"setto" la struct (type) corrispondente ai relativi elementi XML
       tempVD.push_back(tempDati); //che aggiungo al vettore
       levelCounter++;
       }
       if(file.at(i).substr(0,7)=="chiave="){
       tempDati.elemento=file.at(i);
       tempDati.valore=file.at(i).substr(7,file.at(i).length()-7);
       tempDati.lvl=levelCounter; //"setto" la struct (lvl) corrispondente al livello gerarchico dell XML, root=0... child di root=1...
       tempDati.type=1; //"setto" la struct (type) corrispondente ai relativi elementi XML
       tempVD.push_back(tempDati); //che aggiungo al vettore
       }
       if(file.at(i).substr(0,10)=="[commento="){
       tempDati.elemento="commento";
       tempDati.valore=file.at(i).substr(10,file.at(i).length()-11);
       tempDati.lvl=levelCounter; //"setto" la struct (lvl) corrispondente al livello gerarchico dell XML, root=0... child di root=1...
       tempDati.type=1; //"setto" la struct (type) corrispondente ai relativi elementi XML
       tempVD.push_back(tempDati); //che aggiungo al vettore
       }
       if(file.at(i).substr(0,5)=="[fine"){
        levelCounter--; //decremento il livello
       }
   }
   int n=0;
   do{
       cout<<" "<<endl;
       try {
         cout<<tempVD.at(n).elemento<<endl;
       } catch (std::out_of_range& e) {
          cerr << "Errore: " << e.what() << endl;
         }
       try {
         cout<<tempVD.at(n).valore<<endl;
       } catch (std::out_of_range& e) {
          cerr << "Errore: " << e.what() << endl;
         }
       try {
         cout<<"Livello: "<<tempVD.at(n).lvl<<endl;
        } catch (std::out_of_range& e) {
          cerr << "Errore: " << e.what() << endl;
          }
       try {
          cout<<"Tipo nodo: "<<tempVD.at(n).type<<endl;
        } catch (std::out_of_range& e) {
          cerr << "Errore: " << e.what() << endl;
          }
        n++;
        }while(n<tempVD.size());
   return tempVD;
}



int main(int argc, char *argv[]){
    FILE * testo = fopen (argv[1], "r");
    //fopen restituisce 0 nel caso di errore nell'apertura, controllo che l'apertura sia andata a buon fine
    if (testo==0){
       cerr<<"Errore nell'apertura del file!"<<endl;
       system("PAUSE");
       return EXIT_SUCCESS;
       }

    vector<string> parsedFile= parse(testo);
    cout<<"*** FILE DI INPUT ***"<<endl;
    for (int n=0;n<parsedFile.size();++n){
    cout<<parsedFile.at(n)<<endl;
    }

    cout<<endl<<endl<<"*** RICERCA INIZI SEZIONE ***"<<endl;
    vector<Dati> solvedFile= solve(parsedFile);

    cout<<endl<<endl<<"Fine"<<endl;

    try {
            XMLPlatformUtils::Initialize();
        }
        catch (const XMLException& toCatch) {
            char* message = XMLString::transcode(toCatch.getMessage());
            cout << "Error during initialization! :\n"
                 << message << "\n";
            XMLString::release(&message);
            return 1;
        }


        XMLCh tempStr[100];
        XMLString::transcode("LS", tempStr, 99);
        DOMImplementation *impl = 
DOMImplementationRegistry::getDOMImplementation(tempStr);
        DOMBuilder* parser = 
((DOMImplementationLS*)impl)->createDOMBuilder(DOMImplementationLS::MODE_SYNCHRONOUS, 
0);

        DOMDocument *doc = 0;


        parser->release();


    int a;	
    cin>>a;
    return EXIT_SUCCESS;
}




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]