arf 8
New Member
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 14547 sicarie 4,677
Recognized Expert Moderator Specialist
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?
arf 8
New Member
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;
horace1 1,510
Recognized Expert Top Contributor
the statement -
while (getline(infile, x, '\n'))
-
read whole lines at a time, replace it with
which will read words delimited by whitespace
arf 8
New Member
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.
horace1 1,510
Recognized Expert Top Contributor
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
arf 8
New Member
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 replace the text its reversing
eg.
|
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
Subject: how to read it out using c++
Reply | Reply to Author | Forward | Print | Individual Message | Show
original | Remove | Report Abuse
|
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;
char c;
std::string str;
|
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> buf(SIZE);
fread(&buf, 1, SIZE, f);
|
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 filled with a tab
delimited list of 10 columns (floats) and read it into a 2D array.
The length of the columns are all the same, however this will be
variable from text file to text file. Any help (starter code or where
to read) would be much...
|
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
* vector<string>. Now, use istringstream to read read each line
* from the vector a word at a time.
|
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 np # for array/matrix processing
import matplotlib.pyplot as plt # for general plotting
from mpl_toolkits.mplot3d import axes3d # for 3d plotting
wordList=
numFiles = 0
numDataSets = numVectors = sizeVector = 0
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |