C++

Signaler
Messages postés
14
Date d'inscription
mercredi 13 octobre 2010
Statut
Membre
Dernière intervention
26 mars 2013
-
salut a tous,
je suis un debrouillard sur c++ et actuellement j'arrive pas a jumeller getline avec "string".substr....
En effet, dans ma class Instructionset, il y a des substring et les instructions pris via le main avec le getline dans un autre fichier txt. Lorsque j'execute le programme, il ne fait aucune subdivision.

ci joint mon code.

//Instructionset.h

#ifndef INSTRUCTIONSET_H_INCLUDED
#define INSTRUCTIONSET_H_INCLUDED
#include<string>
#include<fstream>
#include
using namespace std;

class InstructionSet
{
private:
string instructionSet;

public:
InstructionSet(string);

string getFirstbits();
string getSReg();
string getDReg();
string getAs();
string getAd();
string getBorW();
string getOffsetSrc();
string getOffsetDst();
string getSelect();

int run();
int convert(string);
};
#endif // INSTRUCTIONSET_H_INCLUDED

//InstructionSet.cpp

#include"InstructionSet.h"
#include<string>
InstructionSet::InstructionSet(string set)
//:instructionSet(set)
{

}

string InstructionSet::getFirstbits()
{
string firstbit=instructionSet.substr(0,4);
cout<<"instructionSet getFirstbits : " << instructionSet.substr(0,4)<<endl;
return firstbit;
}
string InstructionSet::getDReg()
{
return instructionSet.substr(12,4);
cout<<"instructionSet destination Register : " << instructionSet.substr(12,4)<<endl;

}
string InstructionSet::getSReg()
{
string res;
res=instructionSet.substr(4,4);
cout<<"instructionSet source Register : " << instructionSet.substr(4,4)<<endl;

return res;
}
string InstructionSet::getAd()
{
return instructionSet.substr(8,1);
cout<<"instructionSet getAd : " << instructionSet.substr(8,1)<<endl;

}
string InstructionSet::getAs()
{
return instructionSet.substr(10,2);
cout<<"instructionSet getAs : " << instructionSet.substr(10,2)<<endl;
}
string InstructionSet::getBorW()
{
return instructionSet.substr(9,1);
cout<<"instructionSet getBorW : " << instructionSet.substr(9,1)<<endl;

}
string InstructionSet::getSelect()
{
return instructionSet.substr(6,3);
cout<<"instructionSet getSelect : " << instructionSet.substr(6,3)<<endl;

}
string InstructionSet::getOffsetSrc()
{
return instructionSet.substr(16,16);
cout<<"instructionSet getOffsetSrc : " << instructionSet.substr(16,16)<<endl;
cout<<"instructionSet Offset source(integer) : " << convert(instructionSet.substr(16,16))<<endl;
}
string InstructionSet::getOffsetDst()
{
return instructionSet.substr(16,16);
cout<<"instructionSet getOffsetDst : " << instructionSet.substr(16,16)<<endl;
cout<<"instructionSet Offset destination (integer) : " << convert(instructionSet.substr(16,16))<<endl;
}
int InstructionSet::convert(string str)
{
int rs=0;
int mult=1;
for(int i=str.length()-1; i>=0;i--)
{
if(str.at(i)=='1')
{
rs=rs+mult;
}
mult=mult*2;
}
return rs;
}
int InstructionSet::run()
{
}

//main.cpp

#include
#include<string>
#include<vector>
#include
#include<cmath>
#include<conio.h>
#include<fstream>
#include<sstream>
#include"InstructionSet.h"

using namespace std;
inline void keep_window_open() {char ch; cin>>ch;}


int main()
{
cout<<"Hello Word!"<< endl;
ifstream files("C:\\Gettest\\test.txt",ios::in|ios::binary);
if(files)
{
string set;

while(getline(files,set))
{
cout<<"instructionSet : " << set << endl;
InstructionSet myInstructionSet("set");

}
}
else
{
cout<<"Error files not be Found"<<endl;
}

keep_window_open();
return 0;
}





toute sujestion sera la bienvenu
bonne journée



Merci !?