| | |
Reading data from text (Again!)
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Apr 2008
Posts: 2
Reputation:
Solved Threads: 0
Hi folks,
I'm just learning C++ (using Borland C++ Builder) and I am having difficulty reading data from a text file created in Excel. I am trying to read the data into vectors which I can then use in a model that I am building.
The problem is that I get no output to the console application. The code that I am using is as follows:
Any help would be greatfully appreciated.
I'm just learning C++ (using Borland C++ Builder) and I am having difficulty reading data from a text file created in Excel. I am trying to read the data into vectors which I can then use in a model that I am building.
The problem is that I get no output to the console application. The code that I am using is as follows:
C++ Syntax (Toggle Plain Text)
#include <vcl.h> #pragma hdrstop #include <iostream> #include <fstream> #include <iomanip> #include <vector> #pragma argsused using namespace std; int main(int argc, char* argv[]) { // Opening the file ifstream file_in("data.txt"); const int max_char = 15,// Characters expected in header line header_lines = 1; // Header lines to skip // Ignore the header lines for(int j = 0; j < header_lines; ++j) file_in.ignore(max_char, '\n'); // Set up vectors for each column of data vector<int> date; vector<float> maxchl, sst; while(!file_to_read.eof()) { //Set up temporary variables int dt; float chl,tmp; file_in >> dt >>chl >> tmp; date.push_back(dt); maxchl.push_back(chl); sst.push_back(tmp); } // Print all the volts read cout << "\nDate:\n"; for(vector<int>::size_type j = 0; j < date.size(); ++j) cout << date[j] << '\n'; cout << "\nMaxChl:\n"; for(vector<float>::size_type j = 0; j < maxchl.size(); ++j) cout << maxchl[j] << '\n'; cout << "\nSST:\n"; for(vector<float>::size_type j = 0; j < sst.size(); ++j) cout << sst[j] << '\n'; //Pause until a char is entered char r; cin >> r; return 0; }
Any help would be greatfully appreciated.
Last edited by Narue; Apr 16th, 2008 at 1:03 pm. Reason: Fixed code tags, but there was no formatting to begin with.
![]() |
Similar Threads
- reading data using serial port (Visual Basic 4 / 5 / 6)
- reading data from a text file (C++)
- reading data from a text file (C++)
- bold text and blue background for IFRAME (HTML and CSS)
- reading data from text fies in c (C)
- Reading Data from Text (IT Professionals' Lounge)
- Perl/CGI (Reading Data) Part II (Computer Science)
- Help Reading Info in Text File Into an Array (C++)
Other Threads in the C++ Forum
- Previous Thread: Return type of a function
- Next Thread: Memory allocation confusion
Views: 840 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll encryption error file forms fstream function functions game getline givemetehcodez google graph homeworkhelper iamthwee ifstream input int integer java lazy lib linkedlist linux loop looping loops map math matrix memory microsoft newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort string strings struct studio system template templates test text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






