Hello,
i have a problem where i need read dataset from text file and keep them into a vector.
e.g. dataset:
"0012 0033 00045 0044 0047"
Based on this dataset, i need to keep every 4 numbers separately into a vector.
: P
6 14529
Hello,
i have a problem where i need read dataset from text file and keep them into a vector.
e.g. dataset:
"0012 0033 00045 0044 0047"
Based on this dataset, i need to keep every 4 numbers separately into a vector.
: P
Did you have a question about that? In declaring/manipulating a vector or reading input in from a text file?
Did you have a question about that? In declaring/manipulating a vector or reading input in from a text file?
The basic idea is to transfer the dataset from a text file into a vector. From this vector, the manipulation process will be conducted. This dataset as been inserted as "string" in the vector.e.g. "0012 0034 0045 0023 3343 0001". I do not know how to convert/divide this string into a group of characters .."0012" , " 0034" and etc so that i could keep them as a separated data in the vector. Based on my code, each vector will keep the data for the whole string. What is wrong with my code?
This is my code for your reference - int main()
-
{
-
SDTVECTOR Std;
-
SDT TpStd; //declared TpStd -- vector<string>
-
string x;
-
-
ifstream infile;
-
infile.clear();
-
infile.open("staf.txt");
-
-
if (!infile)
-
{
-
cerr << "File could not be opened" << endl;
-
exit(1);
-
}
-
-
while (getline(infile, x, '\n'))
-
-
{
-
TpStd.Em.push_back(x);
-
{
-
Std.push_back(TpStd);
-
TpStd.Em.erase(TpStd.Em.begin(), TpStd.Em.end());
-
}
-
}
-
.
-
-
.
-
.
-
}return;
the statement -
while (getline(infile, x, '\n'))
-
read whole lines at a time, replace it with
which will read words delimited by whitespace
Thanks..It's work. But how about, if there is a several strings and each string is assumed as a single respondent..e.g.
"0111 0233 9449 0022"
"4453 8899 3343 0003"
"4456 4453 2223 1223"
* this case, there are 3 respondents
The question is how the program will know once it reaches at the end of string.
Thanks..It's work. But how about, if there is a several strings and each string is assumed as a single respondent..e.g.
"0111 0233 9449 0022"
"4453 8899 3343 0003"
"4456 4453 2223 1223"
* this case, there are 3 respondents
The question is how the program will know once it reaches at the end of string.
will read whitespace delimeted strings until end of file or error
will read whitespace delimeted strings until end of file or error
Ok.
If i would like to maintain these line of strings (because each string represent for each respondent) put all of data into the vector, where from there i could count or compare them based on these respondents. Should i need to use '\n' in order to separate these strings?
*I need to use the vector because the data is fluctuate from one string to another
Sign in to post your reply or Sign up for a free account.
Similar topics
by: John Flynn |
last post by:
hi,
having problems reading from and writing back to the same file.
basically, i want to read lines of text from a file and reverse them and
write them back to the same file.. it has to...
|
by: pisscot |
last post by:
Lind Apr 13, 6:32 am show options
Newsgroups: comp.lang.c
From: piss...@gmail.com (Lind) - Find messages by this author
Date: 13 Apr 2005 06:32:15 -0700
Local: Wed,Apr 13 2005 6:32 am...
|
by: Jason Heyes |
last post by:
Does this function need to call eof after the while-loop to be correct?
bool read_file(std::string name, std::string &s)
{
std::ifstream in(name.c_str());
if (!in.is_open())
return false;
...
|
by: sshock |
last post by:
Hi all,
I want to read from a file into a vector<unsigned char>. Right now my
code looks like this:
FILE* f = fopen( "datafile", "rb" );
enum { SIZE = 100 };
vector<unsigned char>...
|
by: Ground21 |
last post by:
Hello.
How could I read the whole text file line after line from the end of
file? (I want to ~copy~ file)
I want to copy file in this way:
file 1:
a
b
|
by: RyanS09 |
last post by:
Hi-
I have read many posts with specific applications of reading in text
files into arrays, however I have not been able to successfully modify
any for my application. I want to take a text file...
|
by: arnuld |
last post by:
This works fine, I welcome any views/advices/coding-practices :)
/* C++ Primer - 4/e
*
* Exercise 8.9
* STATEMENT:
* write a program to store each line from a file into a
*...
|
by: Matrixinline |
last post by:
Hi All,
Here is the problem
char* memblock;
std::ifstream file(sFileName, ios::in|ios::binary);
if (file.is_open())
{
size = file.tellg();
|
by: csgirlie |
last post by:
I'm trying to store or arrange three sets of two-dimensional data into three 2xN matrices that are stored as NumPy arrays.
import os # for file handling functions
import numpy as...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |