私のコードにはあちこちにフランス語と英語が少し含まれていることをすべて警告するつもりです。変数や何かを理解していない場合は、質問して無料のフランス語クラスと見なしてください。学校で使用する時間割を作成するプロジェクトがあり、「時間」部分の管理、つまり教授が授業を行うための時間間隔と部屋の作成を担当しています。すべての状況が正しく機能することを確認するために、2 つのクラスが同時に同じ場所で発生しないようにする必要があります。フランス語で「AddsClass」を意味する関数「rajoutcours」では、いくつかのパラメーターを使用します。
- マチエール = 主題
- heure_deb = 開始時刻
- heure_fin = 終了時刻
- date = まあ、それはクラスの日付です
- サレ=部屋。
私の関数では、heure_start (別のクラスが開始する時刻)、heure_end (別のクラスが終了する時刻)、day と room (他のクラスが行われる日とそれらが行われる部屋) の 3 つの変数を作成します。文字列演算子「+」プロパティを使用してこれらの変数を入力し、txt ファイル (他のクラス) の行のすべての文字を 1 文字の文字列に変換して、sstream ライブラリを使用してそれらを追加できるようにします。奇妙なことに、文字列に変換されるのは 1 文字だけですが、他の文字は変換されず、その理由がわかりません。
とにかく、私はこれをよく知っていますが、何日も調べようとしてきましたが、どこに問題があるのか わかりません. ご協力ありがとうございました。
void Utilisateur::rajout_cours(string matiere, string heure_deb, string heure_fin, string date, string salle )
{
ifstream user_in ("Cours.txt"); // txt file where classes are listed
ofstream user_out;
user_out.open("Cours.txt", ofstream::out | ofstream::app);
user_out; //write
string ligne; //line variable which reads the lines of the txt file
string heure_start; // time at which the class starts
string heure_end; // time at which the class ends
string day; // self explanatory
string room; // ie before
int i=0;
int j=0;
int cptr=0;
int a,b,c,d;
stringstream ss; // this is supposed to convert char into string
while (getline(user_in,ligne))
{
for(i=0;i<ligne.size();i++)
{
if(ligne.at(i)=='$' && cptr==0)
{
a=i;
cptr++;
cout << "Premier '$'" << endl; // Keep in mind that the '$' is the delimiter when i write on the txt file, it's also a way to know where I am.
for(j=0;j<a;j++)
{
char tmpc='\0';
string tmps;
tmpc=ligne.at(j);
ss << tmpc;
cout << "Lettre a la case " << j << " : "<< tmpc << endl; //I want to know what's the char in the j-th character of the word
ss >>tmps;
cout << "Lettre string a la case " << j << " : "<< tmps << endl; // I want to display it's string version
heure_start=heure_start+tmps;
}
}
else if(ligne.at(i)=='$' && cptr==1)
{
b=i;
cptr++;
cout << "Deuxieme '$'" << endl;
for(j=a+1;j<(b);j++)
{
char tmpc = '\0';
string tmps;
tmpc=ligne.at(j);
ss << tmpc;// conversion char en string
cout << "Lettre char a la case " << j << " : "<< tmpc << endl; //I want to know what's the char in the j-th character of the word
ss >>tmps;// conversion complète à priori
cout << "Lettre string a la case " << j << " : "<< tmps << endl; // I want to display it's string version
heure_end=heure_end+tmps;
}
}
else if(ligne.at(i)=='$' && cptr==2)
{
c=i;
cptr++;
cout << "3eme '$'" << endl;
for(j=b+1;j<(c);j++)
{
char tmpc='\0';
string tmps="";
tmpc=ligne.at(j);
ss << tmpc;
cout << "Lettre a la case " << j << " : "<< tmpc << endl; //I want to know what's the char in the j-th character of the word
ss >>tmps;
cout << "Lettre string a la case " << j << " : "<< tmps << endl; // I want to display it's string version
room=room+tmps;
}
}
else if(ligne.at(i)=='$' && cptr==3)
{
d=i;
cptr++;
cout << "4eme '$'" << endl;
for(j=c+1;j<(d);j++)
{
char tmpc='\0';
string tmps="";
tmpc=ligne.at(j);
ss << tmpc;
cout << "Lettre char a la case " << j << " : "<< tmpc << endl; //I want to know what's the char in the j-th character of the word
ss >>tmps;
cout << "Lettre string a la case " << j << " : "<< tmps << endl; // I want to display it's string version
day=day+tmps;
}
}
}
}
if(heure_deb==heure_start && heure_fin==heure_end && date==day && salle==room) // I make sure here that the class I'm writing isn't already written in the file and in that case we leave the program.
{
cout << "Impossible d'ajouter un cours ! Un cours de " << matiere <<"a deja lieu à ce moment! Changez d'horaires ou de salles. " << endl;
exit(1);
}
cout <<"ecris" << endl;
user_out << heure_deb << "$"<< heure_fin << "$" << salle << "$" << date << "$" << matiere << endl; // If not, write the new class.
}