1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
{
if(Antal!=0)
{
ofstream Betygs;
string FileNameInput, FileNameOutput;
system("cls");
cout << "\n Vad vill du kalla den h\x84r filgruppen?";
getline(cin, FileNameInput);
getline(cin, FileNameInput);
FileNameOutput ="Lagring\\";
FileNameOutput+=FileNameInput;
FileNameOutput+="-Betyg.txt";
Betygs.open(string(FileNameOutput).c_str());
if(Antal!=0)
{
if(Betygs.is_open())
{
for(int i = 1; i <= Antal; i++)
{
Betygs<<Betyg[i]<<endl;
}
Betygs.close();
}
if( remove( ".txt" ) != 0 )
perror( "" );
puts( "" );
FileNameOutput ="Lagring\\";
FileNameOutput+=FileNameInput;
FileNameOutput+="-Fornamn.txt";
ofstream Namn;
Namn.open(string(FileNameOutput).c_str());
if(Namn.is_open())
{
for(int i = 1; i <= Antal; i++)
{
Namn<<Namn1[i]<<endl;
}
Namn.close();
}
FileNameOutput ="Lagring\\";
FileNameOutput+=FileNameInput;
FileNameOutput+="-Efternamn.txt";
ofstream Efternamn;
system("cls");
Efternamn.open(string(FileNameOutput).c_str());
if(Efternamn.is_open())
{
for(int i = 1; i <= Antal; i++)
{
Efternamn<<Namn2[i]<<endl;
}
Efternamn.close();
}
FileNameOutput ="Lagring\\";
FileNameOutput+=FileNameInput;
FileNameOutput+=".txt";
ofstream LagringsEnhet;
system("cls");
LagringsEnhet.open(string("Lagring\\"+FileNameInput+".txt").c_str());
if(LagringsEnhet.is_open())
{
LagringsEnhet<<"Lagring\\"+FileNameInput+"-Betyg.txt\n";
LagringsEnhet<<"Lagring\\"+FileNameInput+"-Fornamn.txt\n";
LagringsEnhet<<"Lagring\\"+FileNameInput+"-Efternamn.txt\n";
}
LagringsEnhet.close();
}
}
}
|
There's how it creates the files from the start, as you can see they end up in the same directory. This is also mentioned in the file, but should there be double backslashes in the file? I've tried with both Single and Double backslashes but with no difference.
Namn1, Namn2 and Betyg are defined as Namn1[99], Namn2[99] and Betyg[99] in the beginning of the class.
The loop adding one more iteration than necessary SHOULDN'T be a problem as far as I know. But I'm a newbie, I'm not sure.
I've checked if the file is opened correctly, but when I check Betyg, like this:
1 2 3 4 5 6 7 8 9 10
|
while( !FilEtt.eof())
{
getline(FilEtt,Betyg[i]);
i++;
cout<<Betyg[i] (NOTHING SHOWS UP WHEN I EXECUTE THIS!)
cout<<Betyg[0] (Shows up the first and second time it loops.)
cout<<Betyg[1] (Shows up the second time it loops.)
}
|
I find this very strange. Any ideas what might be the issue/s?
Have I messed up somewhere just so that my Printing function won't work?
I mean.. It's just a simple for loop.
1 2 3 4 5 6
|
for(int N=1 ; N!=Antal+1 ; N++ )
{
cout<<" "<<Namn1[N]<<" "<<Namn2[N]<<" Med betyget : "<<Betyg[N]<<endl;
}
|