所以我正在使用 vs 代码,并尝试使用 c++ 输出一个 csv 文件。没有错误,但我目前得到一些奇怪的字符作为输出而不是所需的输出。
这是我的代码:
#include <iostream>
#include <fstream>
using namespace std;
int main(){
ifstream ip("/Users/safdarjamil/Desktop/cab_rides/src/cab_rides.csv");
if(!ip.is_open()) std::cout << "ERROR: File Open" << '\n';
string firstname;
string lastname;
string age;
string weight;
while(ip.good()){
getline(ip,firstname,',');
getline(ip,lastname,',');
getline(ip,age,',');
getline(ip,weight,'\n');
std::cout << "Name: "<<firstname<< " "<<lastname << '\n';
std::cout << "Age: "<<age << '\n';
std::cout << "Weight: "<<weight << '\n';
std::cout << "-------------------" << '\n';
}
ip.close();
}
这是我的 csv 文件:
cool, nice, 26, 78
John, More, 33, 80
yes, no, 22, 70
hello, bye, 27, 65
这是输出:
Name: ��T
[Done] exited with code=0 in 0.53 seconds