C++ :: Putting Data From TXT File Onto Vector Of Class
Oct 18, 2014
I am having trouble putting data from a txt file onto a vector of a class. For instance.
class employee{
setname(string) {
some code
} getname () {
some code
} setid(int)
[Code] ....
How would use my setname function in my class using my vector? I tried doing vec[num].setname(tempname) but it doesn't work. I know it does not work because I have to use .push back for a vector but I don't know exactly how to pushback using the set name function call.
View 10 Replies
ADVERTISEMENT
Jul 7, 2014
I'm trying to pass several integers into the array idAr[10] from an input file using a for loop and then having them output on the console. The output should look like this:
#include <iostream>
#include <fstream>
using namespace std;
[Code].....
View 4 Replies
View Related
Dec 30, 2013
If I want a class with a vector data member, can I specify it as follows?
std::vector< bool > integers( 101 )
I'm having some problems when compiling code.
View 3 Replies
View Related
Apr 4, 2014
The first line of my input file is going to contain some number "T" which will represent the "combination length" of a list of random words. (In this case, they are Taco Bell items). The first number on the second line represents the number of unique items on the menu to get, and the second number on the second line represents the number of unique items that are supposed to be bought.
Basically the input will look like this: 2 3 2 taco burrito nacho
And the output looks like this: burritos nachos nacho taco burrito taco
This is what I have so far:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
int main(void){
int N, T, K;
char menu[N][20];
[Code] .....
What I am trying to get working right now is just to scan a file and put the strings into an array so then I can work on sorting the array. How can I add strings from a file into an array?
View 4 Replies
View Related
Feb 14, 2015
I am at a loss with an assignment. I am supposed to read from a text file, with an input of something like this: alphaproleone,stroke,42 1 and Store it into an array of structures and then output it with each word/number starting on a new line. My current code prints out only the first part, and the "a" in alphaproleone is the actual number "21".
#include <iostream>
#include <string>
#include<fstream>
#include<iomanip>
using namespace std;
typedef struct drugtype {
string name, target;
int effectiveness, toxicity;
[Code]...
View 1 Replies
View Related
Apr 18, 2014
I am trying to put pieces of a csv file into an array, but i only want to put certain pieces of it. This is the information that i have
Player,Current Team, Age , Nat , Position ,From,To,Transfer fee
Gareth Bale, Real Madrid,24,Wales,RW,Tottenham,Real Madrid CF,91000000
Edinson Cavani,PSG,26,Uruguay,CF,SSC Napoli,PSG,64500000
Falcao, Monaco,27,Columbia,CF,Atlético Madrid,Monaco,60000000
Neymar, FC Barcelona,21,Brasil,LW,Santos,FC Barcelona,57100000
Mesut Özil, Arsenal,24,Germany,AM,Real Madrid ,Arsenal,50000000
James Rodríguez,Monaco, 21,Columbia,RW,FC Porto,Monaco,45000000
With this i want to skip the name and team but need age.
View 3 Replies
View Related
Dec 8, 2014
I am trying to use a combination of windows batch scripts as well a C++ program to put users data into one single .CSV file. Right now, I have a batch file that will output data from the command line into multiple .txt files. These files are mac.txt, serialnumber.txt, computermodel.txt, and computer name.txt. What I want to do, is to have users run the batch file, which will in turn run the .exe C++ file which will concatenate all their data into one file, computerinfo.csv. The file format for this file would be to have the mac address, serialnumber, computer model, and computer name all in their own column.
My main issue is that these individual files don't have the format that I would like, but based on the command prompt functions, there isn't really any good format. For example, the mac.txt file has the following format:
Physical Address Transport Name
=================== ==========================================================
xx-xx-xx-xx-xx-xx DeviceTcpip_{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
yy-yy-yy-yy-yy-yy Media disconnected
zz-zz-zz-zz-zz-zz Media disconnected
but all I really want is xx-xx-xx-xx-xx-xx
The other files have other issues with format, but if I can figure out this one then the others should be a piece of cake.
Also, I want the output of this to all go in one row, and as other users run this file, they will go into new rows without touching the rows above.
View 1 Replies
View Related
Jul 7, 2014
Input file:
Course Of Sales.csv
Time,Price ($),Volume,Value ($),Condition
10/10/2013 04:57:27 PM,5.81,5000,29050.00,LT XT
10/10/2013 04:48:05 PM,5.81,62728,364449.68,SX XT
10/10/2013 04:10:33 PM,.00,0,.00,
How to read the csv file with my own vector class. I already have date.h,date.cpp,time.h,time.cpp
How to do the maintest and how to create the vector class
I need to show Date, highest price and Start time(s) of the highest share price
View 3 Replies
View Related
Oct 10, 2013
how to add a list of information from a file to a vector of a class. Here is my code:
Champion_Info.h
#ifndef CHAMPION_INFO_H_INCLUDED
#define CHAMPION_INFO_H_INCLUDED
#include <vector>
#include <string>
[Code].....
View 6 Replies
View Related
May 13, 2013
I need to create a class vector as a template and define operations on vectors.
And this is what I made.
#include<iostream>
using namespace std;
template<class T>
[Code].....
View 2 Replies
View Related
Oct 22, 2013
I am trying to add data from a file that would go into a class that would later go into a vector of a class. I'm not really sure how to do it exactly. Here is the code:
Champion_Info.h
#ifndef CHAMPION_INFO_H_INCLUDED
#define CHAMPION_INFO_H_INCLUDED
#include <vector>
#include <string>
using namespace std;
class Champ_Info {
[Code] .....
View 2 Replies
View Related
Jan 9, 2014
I have a small class with a static int data member. I want to zero init it. I am thinking that making a .cpp file with only one line seems too much, isn't it?
So, can I do it inside the the header file? The variable is going to enumerate how objects were created (so any alternative will do).
View 7 Replies
View Related
Mar 10, 2013
I'm trying to put file data into members of a class. Remember to type in the file name you want to open. Cool feature right? I just had Dbase.txt so I chose that.
Fixed stuff in the .txt. Now I need to figure out why it only does 1 set and then ends.
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
using namespace std;
class INFO {
[Code] .....
Dbase.txt:
Bob
Guy
Programmer
M
9999.99
40
------------------
Little
Guy
Little Brother
M
0.0
3
------------------
View 14 Replies
View Related
Oct 29, 2014
Code:
cout<<"Enter Filename for input e.g(inp1.txt .... inp10.txt):"<<flush;
cin>>filename;
ifstream inpfile;
inpfile.open(filename,ios::in);
if(inpfile.is_open())
[Code] .....
View 8 Replies
View Related
Dec 14, 2014
im passing a vector of a class to a function of another class. But i cant access the data on the classes inside the vector.
Something like that:
class CDummy{
...
public:
string m_name;
[Code].....
Im creating the vector on main() and using push_back with a pointer to an initialized CDummy instance
View 5 Replies
View Related
Jun 7, 2012
I have a cpp app that reads in a number of files and writes revised output. The app doesn't seem to be able to open a file with a ' in the file name, such as,
N,N'-dimethylethylenediamine.mol
This is the function that opens the file :
Code:
// opens mol file, reads in rows to string vector and returns vector
vector<string> get_mol_file(string& filePath) {
vector<string> mol_file;
string new_mol_line;
// create an input stream and open the mol file
ifstream read_mol_input;
read_mol_input.open( filePath.c_str() );
[Code] ....
The path to the file is passed as a cpp string and the c version is used to open the file. Do I need to handle this as a special case? It is possible that there could be " as well, parenthesis, etc.
View 9 Replies
View Related
Oct 28, 2014
I am trying to write my files to another subfolder . Below is my program.
Code:
cat th6.c
#include <pthread.h>
#include <stdio.h>
#include <string.h>
#define SIZE 8
#define NUMELM 8
[Code] ....
I observe my filename along with directory as text in the new file created in sublfolder. This is output.
[cporgs/apue/threads]: mkdir first
[cporgs/apue/threads]: ./a.out test.txt first
test.txt -- first/test.txt
dfdfdfdfdfdfdf-14
dfdfdfdfdfdfdf-14
in thread test.txt first
[cporgs/apue/threads]: cat first/test.txt
dfdfdfdfdfdfdffirst/test.txt
[cporgs/apue/threads]: cat test.txt
dfdfdfdfdfdfdf
I could not able to get from where this filename and folder is getting added.
View 4 Replies
View Related
Sep 27, 2013
On my program I use a counter to count to 10, then i ask for a string, in this case "yes" or "no", during the count, i want to keep the user from putting inputs in, due to the fact that if they put both "yes" and "no" before the program reads the string.
Code:
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <stdbool.h>
#include <time.h>
#include <string.h>
}
[code]....
View 3 Replies
View Related
Dec 25, 2014
I want to get a random number from this function but idk if I did this function right....
int random(int x) {
srand(static_cast<unsigned int>(time(0)));
int randomN = rand();
x = (randomN % 10) + 1;
return x;
}
View 5 Replies
View Related
May 1, 2014
# include <stdio.h>;
int main (void){
float judges[6];
int degree;
[Code].....
View 5 Replies
View Related
Jan 29, 2014
So I have a double array, where I'm inputting float numbers to certain points in an array. Sometimes, the numbers that are printed out are completely different from what I put in.Here is the part of the code:
Code: .
while( token != NULL ) {
num = atof(token);
test[j][i] = num;
printf( "
%s, i is %d, j is %d
", token,i,j );
printf( "number is %f
value test of i,j is %f
[code]....
Why the float num prints out fine, but when put into an array becomes garbage?I'm taking string values from a csv file and turning them into floats, but no problems seem to crop up there.I reset i when appropriate and increment j when needed, so I don't think my problems are from incorrect array values (though they might be)
View 2 Replies
View Related
Feb 8, 2015
I'm having a little problem where after reading a file I'm unable to update my struct with some particular info. It is actually a linkedlist. This is my struct:
Code:
struct node{
int id;
char name[50];
struct node *next;
}*head;
And in my Main function:
Code:
int main(){
int i, t_id, num;
struct node *temp;
char name[50], t_name[50], input_name[50], line[LINESIZE], *value;
struct node *head = NULL;
FILE * ifp = fopen("AssignmentOneInput.txt", "r");
[Code] .....
Basically in the while loop when I input something like this for updating numbers:
Code: temp->id = num; //These are numbers separated by a comma. or this:
Code: strcpy(temp->name,value); //These are names The program crashes
View 11 Replies
View Related
Aug 2, 2013
I have just learned about how one can put functions and headers in different files from the main() function. I was wondering if there is a rule of thumb of when and when not to separate the two, or if it's merely preference. Is there perhaps an "industry standard" regarding this, for those who program in C for a living?
View 4 Replies
View Related
May 2, 2013
I have this code that is supposed to store numbers in one vector and another vector stores pointers to the values in the first vector:
#include <iostream>
#include <algorithm>
#include <sstream>
#include <cstring>
#include <vector>
#include <cstdio>
[Code] ....
However, when I print out the values stored by the pointer vector, the first 2 values are not the same as what the input was. I have tried it with 4 - 10 values and always, the first 2 are not the same as the input but the rest are. I tried printing out the values as they are stored in the vector in the first for-loop and it seems to contain them all, but after that first for-loop, when I try to print *station.front(), it is now changed to something else.
input:
4
1231 234354 4544343 121312
output:
34144320 0 4544343 121312
input:
6
123 2435 353 12221 356567 4544452
output:
21704768 0 353 12221 356567 4544452
View 9 Replies
View Related
Apr 20, 2013
How can push data into the vector <list<Edge>> adjList? adjList[n].push_back (e);//gives error.
struct Edge {
int from_node_number;
int to_node_number;
int weight;
};
vector <list<Edge>> adjList;
Edge e;
for (int n=0; n< graph.size(); n++)
adjList[n].push_back (e);
View 6 Replies
View Related
Dec 14, 2013
Does it use Linked List or Dynamic Array?
I want to know this because if I happen to want to use a lot of insertions and deletions then it is more efficient to make use of Linked List instead of Dynamic Array.
While, if I happen to want to just access random parts of the Array, then Dynamic would be more efficient.
I want to make a 2D game using SDL engine and I need to check whether or not an object is colliding with a list of other objects. (because there would be more then one objects on the map.)
Since I would simply be accessing each object sequentially to check whether or not the object is colliding with another the object in question, and since any of those objects could "die" and be deleted at any time, it makes more sense to use Linked List then a Dynamic Array.
View 8 Replies
View Related