How can I resolve debug error?
주열 박
0
Reputation points
I used visual studio to code c++.
How can I fix this error?
My code
#include <iostream>
#include <fstream>
#include <string>
int main()
{
using namespace std;
string filename = "C:/Users/park7/Desktop/console/data.csv";
ifstream csv(filename);
string s;
if (!csv.is_open()) {
cout << "파일 열기 실패: " + filename << endl;
return 1;
}
auto old_prec = cout.precision();
cout.precision(3);
while (getline(csv, s)) {
int a, b;
string col1 = "", col2 = "";
if (s == "") continue;
if (s.find(',') == -1) continue;
col1 = s.substr(0, s.find(','));
col2 = s.substr(s.find(',') + 1);
a = stoi(col1);
b = stoi(col2);
cout
<< a << "+" << b << "=" << a + b << endl
<< a << "-" << b << "=" << a - b << endl
<< a << "*" << b << "=" << a * b << endl;
cout
<< a << "/" << b << "=";
if (b == 0)
cout << "0으로 나눌 수 없음" << endl;
else
cout << (float)a / b << endl;
cout << endl;
}
cout.precision(old_prec);
csv.close();
return 0;
}
data.csv
Sign in to answer