C++ :: Value Not Stored Into Vector After Reading File
Oct 21, 2013
Reposting this as I deleted my pervious post because I missed out some parts of the codes.
I am trying to read a textfile containing some informations in this format,I am able to extract everything except the itemId.
View 2 Replies
ADVERTISEMENT
Jan 26, 2014
My program writes a vector to a file in binary. I want to erase the vector, then read the file to repopulate the vector then display.
Basically I want to erase the RAM memory and be able to use the file as memory. This is my current code but it is not reading the file correctly. I have checked the file to see that the writing part is working.
void read_from_file(vector<Info> &vector)
{fstream file;
file.open("info.dat", ios::binary | ios::in);
if (file.fail())
{
cout<<" FILE DOES NOT EXIST ";
system("pause");
[Code]...
View 7 Replies
View Related
Dec 10, 2014
if I want load the file as vector and I want to show on the screen using the new loop for why it only show the last lopp this is a example of my thought why is this not right?
int numb[3];
ifstream output;
output.open("1.dat");
while(!output.eof())
{
output>>numb[3];
}
//assuming there are 3 number in vector
for(int i=0; i<2;i++)
{
cout<<numb[i];
}
View 4 Replies
View Related
Apr 23, 2013
Creating a Vector Array + Reading a file ....
View 1 Replies
View Related
Feb 5, 2014
I need to create a program which could create text files of the bits stored in avi file/binary file. My first requirement is to show 0s and 1s in the text representation . My second requirement is to create an avi file from this text file. I have tried few codings but either they give me error or they not playing the reconverted binary files.
View 6 Replies
View Related
Feb 24, 2015
I am/we developing in C and we have a number of different programs. We also have problem to keep track of different versions of a specific exe file.
Is there any way to add version number when build a file so the version is added in the properties.
I doing this in a MFC c++ project in a .rc file. Is there a way (or a similar way) of doing this in C? Here its stored in the details section with product version 6.0.8:
View 6 Replies
View Related
Jun 21, 2014
I am trying to build a employee management system using C, and I have done alot so far. Everything seems to work fine, but then I thought that I should let the user store the data of their employees permanently, therefore I created a file and then I store the user's given data in the txt file.
Here is the code:
#include<stdio.h>
#include<conio.h>
#include<string.h>
[Code].....
But there is some problem, and I don't seem to understand what is the problem in the code, it's just that whenever the user enters any id to search, and presses any key then nothing appears just a blank screen! I wanted to know that how can I check the ID from the text file and then display the details of the employee of that id!
View 1 Replies
View Related
May 15, 2013
I have a table in my database that has a 3 fields.
RuleID | RuleName | Rule
the ruleID is a randomly generated string of characters, RuleName is the name the user gives to the rule, and the Rule field is about 600 characters long and is just XML text.
I want to read that Rule field from the database and use it inside the function below.
private static List<MenuItem> LoadRules(bool evaluationType)
{
//string path = HttpContext.Current.Server.MapPath(string.Format("/Rules/{0}/{1}/", ip, evaluationType ? "Evaluation" : "Execution"));
[Code]...
This function loads an xml file from a static location and parses out some information to a context menu.
BUt i'm culeless on how to have the function read the xml info found inside my database.
View 1 Replies
View Related
May 5, 2014
I am trying to compare a string that i have entered with a set of strings that have already been stored in a file. I am using strcmp function but i am not getting the result.
Code:
printf("
Enter string:");
scanf("%s",&m);
ptr_file =fopen("abc.text","r");
[Code] .....
View 10 Replies
View Related
Sep 2, 2013
how to save text stored in an array to a txt file. can sum1 how to save the text in an array to a file/txt file......
View 7 Replies
View Related
Mar 13, 2014
Ok so when the program runs the first function the data is stored and displayed in the file. The second function is supposed to read the name entered, compare it to the ones in the file then take the price with it BUT I seem to have done something wrong when reading the files (or maybe it has to do with the global function I'm not sure). Here's parts of the code :
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
[Code]....
View 7 Replies
View Related
Sep 23, 2013
This seems like a fairly straight forward assignment. Load up a file that contains a series of int values stored in ASCII and print out the ASCII characters to the console.
The problem I am having is that I am getting the numerical value of bytes ("40" for 10 numerical values, "200" for 50 values). The numbers are generated randomly by another file, but I can control how many numbers are generated. For example, if I type in:
shell% cat tempfile
the output is as follows:
/8?qE?. Y4?(T???a???%@
but when I try to run it with my program:
shell% ./intcat tempfile
the output displayed is:
40
Code:
#include <stdio.h>
#include <assert.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdlib.h>
int main(int argc, char *argv[]){
//check if arguments match
[Code] .....
View 10 Replies
View Related
Jul 11, 2014
I am making a multiple quiz program. So everything is working fine, except for the part where i'm trying to add a highscore for each user which is being stored in a binary file. I have added a sample of the program containing the error. This isn't the actual program, which is very long.
class user { //The collection of all info pertaining to the users
char user_id[50];
public:
int hscore1;
user() {
strcpy(user_id,"NULL");
hscore=0;
[Code] ....
View 1 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
Jan 16, 2013
Consider the following piece of Code:
int ReadNumbers() {
int num;
vector<int> x;
cout << "Enter Numbers" << '
[Code] ....
The while loop is expected to terminate when the user provides an Invalid Input. But this while loop behaves unexpectedly when the user provides a 'Newline' input (by pressing Enter) and becomes an infinite loop. How can I prevent this from happening? Also I've heard that expecting invalid inputs isn't good code design. Is this true? If yes, then how can I solve my question without expecting Invalid Inputs?
View 10 Replies
View Related
Nov 26, 2013
Program background: Ticket Sales Details You will sell tickets in advance and at the door. Prices for buying in advance and at the door will be given. Also, the total number of tickets sold in advance will be given. Each guest will have a unique number. If there are n tickets sold in advance, then these guests will be numbered 0 through n-1. As the event starts, requests to buy tickets at the door may be made and these guests will be numbered sequentially, starting at the lowest unassigned number. The maximum number of guests will be 1000. The first line of the file contains the following three values, separated by spaces: Cost of the presales tickets (in dollars), Cost of the tickets at the door (in dollars), and the number of presale tickets. The first two values will be positive real numbers to two decimal places and the last will be a positive integer.
The second line of the file will contain one positive integer representing the number of auction items followed by a positive real value to two decimal places (at most) representing the minimum bid increment, in dollars. The first value is guaranteed to be 1000 or less and the second will be in between 1 and 50, inclusive.
The third line of the file will contain all the prices of the auction items, in dollars, separated by spaces, in order. Thus, the first price is the price of item 0, the next price is the price of item 1, and so on. These values will be real numbers represented to up to 2 decimal places.
The fourth line of the file will contain the three following positive integers pertaining to the raffle: the number of raffle tickets available, the cost of a raffle ticket in dollars, and the number of raffle prizes. (It's strange to have raffle tickets that don't cost a whole number of dollars.)
The fifth line of the file will contain each of the values of the raffle items, in dollars, separated by spaces, in order. Thus, the first price is the price if item 0, the next price is the price of item 1, and so on. These values will be real numbers with upto 2 decimal places.
The sixth line of the file will contain ten positive integers representing the number of each of the drinks 0 through 9, in order, that are in stock.
The seventh line of the file will contain ten positive real numbers with upto 2 decimal places representing the price of each of the drinks 0 through 9, in order.
The eighth line of the file will contain a single positive integer, numEvents, representing the number of events that occur at the charity ball. These events are split into two groups: actions by guests at the ball and awards given (raffle, auction, person, totalrevenue). All of the actions precede all of the awards. You will produce exactly one line of output for each event described. Here are the formats of each event that could occur:
If a patron buys a ticket at the door, a command will be on a line by itself:
BUY TICKET k
where k is a positive integer indicating the number of tickets bought at the door. These guests will be numbered as previously mentioned. You are guaranteed that the total number of tickets bought, including presales, will not exceed 1000. This is what I have so far and I cannot figure out why it wont calculate the total revenue. I am not completely sure if it is even accessing the if statement in main.
Code:
#include <stdio.h> #include <stdlib.h>
#include <string.h>
#define N 1000
[Code].....
View 4 Replies
View Related
Nov 7, 2014
I am reading a file then printing the data onto the other file. It is working, however when I check to see if each variable is being properly set after reading the file a issue arises.
Example of the file being read
Code:
Vehicle PV50CAN passed camera 1 at 05:33:26.
Vehicle W867BRO passed camera 1 at 05:33:29.
Vehicle KQ63ARU passed camera 1 at 05:33:38.
Vehicle K954ITQ passed camera 1 at 05:33:40.
Vehicle V220MXB passed camera 1 at 05:33:42.
[Code] .....
View 14 Replies
View Related
Jan 17, 2013
I want to know how mutex is working in process synchronization. Where these mutexes are stored in memory how another process know about this mutex?
If two different mutexes are having same name what will happen?
View 6 Replies
View Related
Apr 9, 2014
How do you use a stored procedure with a WebGrid? Our coding standard say we cannot write sql statement directly in the code to include HTML.
[var Grid = new WebGrid(DB.Query("Select * from Menu")]
The above call must be a call to a stored procedure.
View 4 Replies
View Related
Jan 28, 2014
I am trying to write a program that will open a file with 2 points, take those points, determine what quadrant those points are in, and save the result back into the same file without truncating the data.
I'm having some trouble with my file I/O. I can't get my program to read the two values for X and Y that I put in the points.txt file. It simply uses whatever random number was used last time in that block of memory. In my points.txt file I put something like "4 -5" and it wont assign those numbers to my X and Y variables. I believe the issue is on line 25
#include <iostream>
#include <fstream>
using namespace std ;
int main() {
//defining X and Y
double X, Y ;
[Code] ....
View 14 Replies
View Related
Jan 29, 2012
I know that memory addresses in the stack can contain either values or references to other memory addresses, but do these memory addresses also contain methods or are the methods themselves located in the heap?
The confusion comes from the fact that in C# a delegate variable can be assigned either a method's identifier, an inline function, a lambda expression, or a new instance of the delegate type with the method's identifier passed as an argument to the constructor. My guess is that assigning the method's identifier directly to the delegate variable is just a simplified way of calling the delegate type's constructor with the method's identifier as an argument to the parameter, something that the compiler handles for you.
But even in this last case, the delegate variable is said to point toward the method itself. In that case, does it mean that methods are stored in the heap, just as reference type values are?
View 2 Replies
View Related
Jan 12, 2015
when i compile and run it it gives me the number 0 and not the proper number stored in array.
Code:
#include <stdio.h>
int main()
{
int myArray[11] = { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 };
}
[code]....
View 4 Replies
View Related
Aug 23, 2014
For example when I have:
Class A{
B objectB;
};
Now when I instantiate the object of class A like:
main(){
A objectA;//option 1
A* pObjectA = new A();// option2
}
How is objectB stored in memory (stack heap etc.) for both options??
View 1 Replies
View Related
Dec 5, 2013
Making a game of checkers on C++ win32, visual studio
when i want a piece to move, i type:
cout << "What piece do you want to move? (C4)" << endl;
i type in 'cin' after to get the players input, but how do i get it to store the players input in a certain variable? im going to have a list of variables:
string a1
string a2
string a3
etc
so if the user types in a2, it automatically goes to that variable and then asks the user "where do you want the piece to be moved to?".
View 6 Replies
View Related
Feb 11, 2015
So I'm trying to delete a value stored inside one of my vectors but I can't accomplish this. My attempts are down below. I've commented out one attempt since it gives me errors. How can I do what I am trying to do?
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<vector<int> >row;
vector<int> newColumn;
[Code] ....
View 10 Replies
View Related
Jan 5, 2014
If I am reading data from a .txt file with a person's last name and first name (e.g. Miller Andrew), How do I output the same data with the first name followed by the last ?(e.g. Andrew Miller) Do I use the ignore function?
View 2 Replies
View Related