-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprintcolumn.cpp
More file actions
40 lines (34 loc) · 1.21 KB
/
printcolumn.cpp
File metadata and controls
40 lines (34 loc) · 1.21 KB
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
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
using namespace std;
void printColumn(const std::string& filename, int columnIndex) {
ifstream file(filename);
if (!file.is_open()) {
cerr << "Failed to open file: " << filename << endl;
return;
}
string line;
getline(file, line); // Optionally skip the header if not needed
while (getline(file, line)) {
stringstream ss(line);
string cell;
int currentColumn = 0; // Initialize to 0 for each new line
// Ensure you are using the correct delimiter. If unsure, check the actual CSV file.
while (getline(ss, cell, ';')) { // Change ';' to ',' if your file uses commas
if (currentColumn == columnIndex) {
cout << "check 2" << endl;
break; // Stop processing this line once the required column is found
}
currentColumn++;
}
}
file.close();
}
int main() {
string filename = "C://Users//myakh//CLionProjects//project_3//Fraudulent_E-Commerce_Transaction_Data.csv";
int columnIndex = 2; // Specify the column index to print (0-based)
printColumn(filename, columnIndex);
return 0;
}