Apr 12, 2018 at 6:37pm UTC
I tried debugging it when the error window came up by clicking continue and a breakpoint poped up at min = stoi(temp); which is in the Read Method. idk why though. Idk if this helps but i'm using a static library containing all the classes then linking it to main. but i see no errors
main.cpp
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
#include <iostream>
#include "Album.h"
using namespace std;
int main()
{
Song total;
int choice;
string m_filename;
Album x;
cout << "Album Program" << endl;
cout << "----------" << endl;
cout << "1 - Read ablbum info from a file" << endl;
cout << "2 - Write album info to a file" << endl;
cout << "3 - Show all album info on screen" << endl;
cout << "4 - Show ablum time on screen" << endl;
cout << "5 - Exit" << endl;
cout << "Enter Choice: " ;
cin >> choice;
cout << endl;
cout << "Enter File Name: " ;
cin >> m_filename;
for (int i = 0; i < 6; i++)
{
switch (choice)
{
case 1:
x.Read(m_filename);
cout << "Enter Choice: " ;
cin >> choice;
break ;
case 2:
x.Write(m_filename);
cout << "Enter Choice: " ;
cin >> choice;
break ;
case 3:
x.Display();
cout << "Enter Choice: " ;
cin >> choice;
break ;
case 4:
x.CalcTotalTime();
cout << "Enter Choice: " ;
cin >> choice;
case 5:
return 0;
}
}
return 0;
}
Album.cpp
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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
#include "Album.h"
#include <fstream>
#include <iostream>
#include <iomanip>
using namespace std;
Album::Album()
{
Title = "no name" ;
}
string Album::GetTitle()
{
return Title;
}
void Album::SetTitle(string NewTitle)
{
Title = NewTitle;
}
Time Album::CalcTotalTime()
{
int TotalMin = 0;
int TotalSec = 0;
Time A;
for (int i = 0; i < 5; i++)
{
TotalMin = TotalMin + S[i].GetTime().GetMinutes();
}
for (int i = 0; i <= 5; i++)
{
TotalSec = TotalSec + S[i].GetTime().GetSeconds();
if (TotalSec > 59)
{
TotalMin++;
TotalSec = TotalSec - 60;
}
}
A.SetMinutes(TotalMin);
A.SetSeconds(TotalSec);
return A;
}
void Album::Read(string filename)
{
string Country;
string AlbumName;
string SongTitle;
string temp;
ifstream Read;
// Time m_Time;
// int sec;
// int min;
Read.open(filename);
m_Artist.SetName(AlbumName);
m_Artist.SetCountryofOrigin(Country);
getline(Read, Title);
getline(Read, AlbumName);
getline(Read, Country);
for (int i = 0; i < 6; i++)
{
Time m_Time;
int sec;
int min;
getline(Read, SongTitle);
S[i].SetTitle(SongTitle);
getline(Read, temp);
min = stoi(temp);
m_Time.SetMinutes(min);
getline(Read, temp);
sec = stoi(temp);
m_Time.SetSeconds(sec);
S[i].SetTime(m_Time);
}
}
void Album::Write(string filename)
{
cout << "Enter File Name" << endl;
cin >> filename;
ofstream Write;
Write.open(filename);
Write << GetTitle() << endl;
Write << m_Artist.GetName() << endl;
Write << m_Artist.GetCountryofOrigin();
for (int i = 0; i < 6; i++)
{
Write << S[i].GetTitle() << endl;
Write << S[i].GetTime().GetMinutes() << endl;
Write << S[i].GetTime().GetSeconds() << endl;
}
}
void Album::Display()
{
cout << setw(12) << "Title:" << GetTitle() << endl;
cout << setw(12) << "Artist:" << m_Artist.GetName() << endl;
cout << setw(12) << "Title:" << m_Artist.GetCountryofOrigin() << endl;
}
Last edited on Apr 12, 2018 at 7:34pm UTC
Apr 12, 2018 at 8:42pm UTC
So I didnt see anything that raised my suspicion but i saw that the int min wasnt never given a value. I'm still not sure if thats the problem but i set min and sec to 0 reran it and again it picked up a breaker but in a different location, now in the main.cpp cout << "Enter Choice: " ;
and I just dont see whats wrong with that code.
Edit: nevermind its still at the min = stoi(temp);
Last edited on Apr 12, 2018 at 8:46pm UTC
Apr 12, 2018 at 9:04pm UTC
So in the debugger i noticed my temp has No value at all. So i made temp equal 0 temp = '0' ;
right before the loop and it seems to got rid of the error but still the program isnt working properly
Apr 13, 2018 at 12:19pm UTC
Ok, the next step is to find out why it didn't have a value.
Probably sth. wrong with your read function.
Without knowing the file format it's impossible to tell.