C++ :: Displaying File The Same Way It Was Made?
Apr 18, 2014
If I create a file that looks like this for example,
car 2 4 6 8
truck 1 2 3 4 5 6
plane 4 5 6 7 9
Whenever I go to open it back up like this,
ifstream inputFile;
string line;
inputFile.open("file.txt");
while (inputFile>>line) {
cout << line << endl;
} inputFile.close();
return 0;
}
It displays output like this,
car
2
4
6
8
How can I get it to display like above?
View 2 Replies
ADVERTISEMENT
Oct 2, 2013
I want to monitor a text file. So far what I have is the program reads and prints the names in the file to standard out. When the program reaches the end of the file, it closes.
I want the program to stay active and continue to print names as they are saved to the text file.
I was toying with FindFirstChangeNotification function, but it seems that returns a handle so I'm back to the drawing board.
View 1 Replies
View Related
Jun 19, 2014
I dont know anything about filestreams. I want to record the files that the customer bought, total, cash and change.
Here's my code.
// Create a program that will initiate a purchasing system for registered agents in an agency.
#include<iostream>
#include<windows.h>
#include<conio.h>
#include<fstream>
#include<string>
using namespace std;
void password();
[code]....
View 1 Replies
View Related
Sep 30, 2014
I have a client/server program. My Client process spawns my server process using a `fork()` and `system()` call. The client and the server are meant to communicate to each other through named piped, that is a requirement of my homework. The client and the server are supposed to initially send a message to the other one, through a pipe, to confirm that a connection is made. My issue is that my client is trying to open one of the named pipes before the server has a chance to make it. This doesn't always happen though. Occasionally, it will run fine. Is there some way to synchronize this?
My overall goal is to get a filename and search target from the user, send those to the server through a named pipe. And the server searches for the target and sends info back.
OUTPUT:
Client: PID 2986 - Running on Tue Sep 30 20:59:28 2014
Client: PID 2986 - Enter File Name: largeSampleText.txt
Server PID 2988 - Running on Tue Sep 30 20:59:32 2014
Server: PID 2988 - Synchronized to Client.//This means the client-to-server fifo is working
There was an error opening serverToClientfifo//This means client couldn't open the server-to-client fifo
error is: 2//This means the fifo doesn't exist yet
[Code] ....
CORRECT OUTPUT:
Client: PID 2542 - Running on Tue Sep 30 20:58:44 2014
Client: PID 2542 - Enter File Name: largeSampleText.txt
Server PID 2557 - Running on Tue Sep 30 20:58:54 2014
Server: PID 2557 - Synchronized to Client.
[Code] ....
RELEVANT CLIENT CODE:
int main() {
char requestedFileName[1024];
//Get initial information on the client
pid_t clientPID = getpid();
time_t currentTime = time(0);
char* stringTime= ctime(¤tTime);
[Code] ....
I tried creating both of my fifos in my client and my output changed to this
Client: PID 3150 - Running on Tue Sep 30 21:23:17 2014
Client: PID 3150 - Enter File Name: largeSampleText.txt
Client: PID 3150 - Enter Target:
Server PID 3153 - Running on Tue Sep 30 21:23:21 2014
was
Client: PID 3150 - Input File >>>largeSampleText.txt<<<
Client: PID 3150 - Target >>>was<<<
Client: PID 3150 - Synchronized to Server
Server received unexpected connection message
Message: was
Terminating
So It appears like the client went ahead and put `requestedFileName` and`requestedTarget`into the pipe and the server read out `requestedTarget` instead of the connection message. Not sure why though
View 1 Replies
View Related
Jul 19, 2013
So I'm really stuck trying to figured this bug on the program that is preventing me from displaying the text of my program..
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
#include <stdio.h>
using namespace std;
int main () {
ifstream infile;
ofstream offile;
[Code] ....
View 3 Replies
View Related
May 25, 2012
I want to display a bmp file of resolution 600*420 (using c compiler like code block ) by manual loading. I tried to display the image by loading the pixel value. but this method has a limitation that it take up pixel value of image upto 64kb size.
So now i am trying to load it manually. What are the steps that i has to follow, what are the header files that i has to use ?
My system specification are windows xp professional , intel pentium 4 cpu. I don't know where to start ,does this method has any limitaton ,...etc ........
View 2 Replies
View Related
Jan 19, 2014
I'm working on a program that can load all words from a dictionary "English2.txt" (it's attached to the post), then put every word into a 2-dimensional matrix (every line is reserved for one word) and display them. After loading every word into a matrix, when I try to display first 8 words with printf, I can't do it without '' at the end of a line. Otherwise only the 8th word is displayed... What's more, when I try to read the length of the first word with strlen, it says, that it has 4 characters (in fact there are only 3 and it's the word "AAA"). What could be the reason for that?
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
int main()
{
FILE *fp;
char buffer[32];
[Code]...
View 4 Replies
View Related
Dec 6, 2013
i have turbo c++ 3.0 installed . my program is compiled without error and is running. but when i choose option to display scores in the consol , it hangs . check my code. i have to run this on same compiler. i just want to display all the contenets of text file .
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
[Code].....
View 4 Replies
View Related
Mar 6, 2014
Is it possible to display data from a textfile and also save data in to a textfile, reason being is for me to create back-ups of data into a textfile hidden somewhere in a safe location in the local disk or server in case of database error and failure.
View 3 Replies
View Related
Jan 28, 2015
It's a shock to me seeing the partial display of variables being picked by intellisense. I am working in VS2013 environment. I have a project, in the project Settings file I created string variables of about 100 to be accessed across the files for the project, like this:
A example of thew variable it worked for
public static String TradeportAccordionSystemAdminInstitutionManagement = Settings.Default.[b]TradeportAccordionSystemAdminInstitutionManagement[/b];
An example of the variable it did not work for
public static String TradeportAccordionSystemAdminInstitution = Settings.Default.
So, does it mean that the Settings file has a limit of variables that should be declared in it?
View 2 Replies
View Related
Sep 28, 2013
I have a file in which I have written a structure called "Record".
Here is the struct definition:
Code:
#define IDSIZE 10
struct Record{
char id[IDSIZE];
int score;
};
Here's the code where I wrote to the file:
Code:
Record record;
char* id = "H12345678";
int score = 50;
record.id = id;
record.score = score;
file.write((const char*)&record, sizeof(record));
}
Here's a screenshot of the file in windows: [URL].... To the left is the id, 9 characters. To the right, well I'm assuming that's the score that I wrote.
And here's the problem, reading from the binary file:
Code:
Record record;
fstream file(argv[1], ios::in | ios::binary);
if(!file){
cerr << "Could not open the file." << endl;
return 1;
}
char* id = new char[IDSIZE];
[Code]...
The ID reads perfectly. The score...always returns 0, despite that it should show "50".
View 4 Replies
View Related
Mar 7, 2013
You are given an integer, perhaps a very long long integer, composed of only the digits 1 and/or 2. You have the ability to change a 1 digit into a 2 and a 2 digit into a 1 and must determine the min. number of changes that you can make resulting in no 2 digits remaining in the number that are in a position(in terms of powers of ten) higher than any 1 digit.
example:
2222212 number of changes:1
1111121 1
2211221 3
1122112 2
no negative numbers.
how to get started. Also I'm not allowed to use anything related to arrays or sorting.
View 6 Replies
View Related
Feb 13, 2014
I want to make an encapsulated surface class that keeps track of important aspects about a surface. I have it started, except when I test the .onDraw() function, nothing appears on the screen. My Code is below:
#include "NSurface.h"
NSurface::NSurface() {
surface = NULL;
}
NSurface::~NSurface() {
SDL_FreeSurface(surface);
[code]....
why nothing is blitting to the screen when I test that class.onDraw() and SDL_Flip(screen)?
View 1 Replies
View Related
Feb 8, 2015
I want to know how to respond to a request made by a mobile application (preferably Android) through a desktop software. So for example if there is a button on the mobile app named 'do something and a user clicks it, I want the desktop software to respond to that request and 'do something
So what I was thinking was to upload a file to a server when the button on the app is clicked and add a timer to the desktop software to connect to the server and read the file and respond accordingly.
Is this how it is usually done or am I going about this the wrong way? Im developing the app in C# (Xamarin) and the desktop software in C# as well.
View 6 Replies
View Related
Nov 25, 2012
Running c in jgrasp.. i am getting error has gcc not found.
View 4 Replies
View Related
May 8, 2015
implementing a game of chess, i was able to easily implement the grid with an 8x8 multidimensional array.but here is the case I need to implement a grid made of hexagons(six sided but in future may be seven sideded or eight may be needed): like a beehive something.
How can such a grid be implemented in c++ taking notes of coordinates and borders and stuff? From where i can start working from? this grid has to be just like the chess grid only we got six sided boxexs instead of four,
View 6 Replies
View Related
Jan 6, 2015
I am supposed to convert a string made of many numbers between every number spaces are between, to an integer variable for every number..
How am I supposed to get over this problem?
Example: String: " 322 52 231"
View 1 Replies
View Related
May 3, 2014
Is it possible in C to instantly react to keystrokes made in console?For example, consider the following code:
Code:
#include<stdio.h>
int main(int argc, char *argv[]) {
char ch;
printf("Enter a sentence...
");
[code]....
The evaluation of the if statement inside the loop will not occur until the Enter key is pressed on keyboard.To my best understanding, It just pushes the keystrokes to some buffer, and when the '' is introduced, it evalutes the characters one by one.Is there an elegant way to instantly react to keystrokes in C?
View 5 Replies
View Related
Apr 25, 2013
I am doing a c project .it is a system that stores the name of txt format reports made by students and opens them.
View 1 Replies
View Related
Jul 9, 2014
I was going through Singleton design pattern and get to know that objects can be created only by static function of that class and constructors are make private.
My question is, why assignment operators are not made private through which we can create a copy of already existing object.
I tried below code and assignment works, so I have new object sc3. I know that its referring to memory of sc1 but finally I was able to create object without using static function.
Also, why copy constructor not made as private.
Below is code:
#include <iostream>
using namespace std;
class Singleton {
private:
static bool instanceFlag;
[Code] .....
View 3 Replies
View Related
Feb 20, 2013
Write a C program that calculates the final value of an investment made in a TSX Market Linked GIC.
Specification
The return on this type of GIC (Guaranteed Investment Certificate) is based on the initial investment, the number of years (1, 2 or 3), a minimum return rate, a maximum return rate, a participation rate, the values of the TSX (Toronto Stock Exchange) index at specified intervals during the years, and the type of averaging of these values. The final investment value can only be calculated once all the TSX values are known.
If averaging is not used the TSX rate is determined from the opening and closing values only. If averaging is used the TSX rate is determined by calculating the TSX average at 6 monthly intervals, then is based on this average relative to the opening value. The TSX rate is then multiplied by the participation rate. If this new rate is below the minimum rate, then the minimum rate is used, and if it is above the maximum rate, then the maximum rate is used. Rates are printed to 2 decimal places, and the final investment is rounded down, and formatted using commas.
Only round down for the final investment. If the TSX rate is negative do not print the line for rate adjusted for participation. Assume that the final investment is less than one million dollars. (Hint: if you need to print leading zeros in a number, use the %0m.n format: example - the format specifier %06.2f prints 4.56 as 004.56)
Example 1: See below; averaging is not used, so TSX rate = (107-100)/100 = 7%. After using a participation rate of 80%, get 5.6% (which is between min & max rates).
Example 2: See below; averaging is used over 5 values to get a rate of 68% which equals 54.4% due to participation. This is more than the max rate, so the max rate is used.
The GIC calculator must use the following layout exactly.
+------------------------------------+
| TSX MARKET LINKED GIC CALCULATOR |
+------------------------------------+
Enter initial investment : 1000.00
Enter number of years [1,2,3] : 3
Enter minimum and maximum rates [%] : 1 20
Enter participation rate [%] : 80
Enter if averaging used [1=yes,0=no]: 0
Enter open and close values : 100 107
TSX rate . . . . . . . . . . . . . . 7.00%
Rate adjusted for participation . . 5.60%
Final investment . . . . . . . . . . $ 1,056.00
+------------------------------------+
| TSX MARKET LINKED GIC CALCULATOR |
+------------------------------------+
Enter initial investment : 2000.00
Enter number of years [1,2,3] : 2
Enter minimum and maximum rates [%] : 1 20
Enter participation rate [%] : 80
Enter if averaging used [1=yes,0=no]: 1
Enter 5 TSX values : 200 190 320 430 540
TSX rate . . . . . . . . . . . . . . 68.00%
Rate adjusted for participation . . 54.40%
Maximum rate is applicable . . . . . 20.00%
Final investment . . . . . . . . . . $ 2,040.00 i wrote something like
Code:
#include <stdio.h>
int main (void)
{
int years, minimum, maximum, partrate, x, open, close, tsxvalue;
float investment, tsxrate, y, finalinvestment, maxrate, minrate;
printf("+------------------------------------+
[Code] ....
I don't know what the exact calculation should be here now to get the rest....so I'm stuck here
View 2 Replies
View Related
Mar 4, 2012
Code:
class A
{
std::map<std::string, Unit*> aMap;
class B
[Code] .....
This code snippet results in "A non-static member reference must be made relative to a specific object". When I make callA() static, this error goes away, but there is problem with aMap.
View 2 Replies
View Related
Dec 21, 2012
I have a text file that is divided into blocks:
#1
1:animal
2:food
3:moves
4:oxygen
#2
1:eats:2
2:breaths:2
3:can:1
4:is a:1
#3
1:1:2
1:3:3
1:2:4
And the following program that displays block by block:
StreamReader streamReader = new StreamReader("G:LAB123LABWORK2.txt");
int block = 0;
while (!streamReader.EndOfStream) {
string line = streamReader.ReadLine().Trim();
if (line.CompareTo("") == 0)
[Code] .....
My problem is am supposed to add a verification code so that if i put a string e.g 1:?:? it returns the block where the string is found and gives of all possible answers.
Attached Files : LABWORK2.txt (240 Bytes)
View 2 Replies
View Related
Jul 20, 2013
I'm trying to display the contents of this map. I'm having some trouble where the program ceasing to display after "Index Contents."(lines 33 -40) If I move the display for loop right where I'm inserting the values (line 52) into the map I get output. I'm not sure where bug is.
#include <iostream>
#include <fstream>
#include <vector>
#include <sstream>
#include <regex>
#include <iterator>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
typedef istream_iterator<string> isIterator;
typedef map<string, string> indexMap;
[Code] ....
View 1 Replies
View Related
Mar 5, 2015
I am trying to write a c program to convert centimeters to inches and then to feet. I have most of the code written but not sure how to debug it. I keep getting "0" as all of my output.
#include <stdio.h>
// Main Function
int main(void)
[Code]....
View 2 Replies
View Related
Jan 6, 2012
I got assignment at my school to display 2D array like this:
This is default array:
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
Now I have to print the default array like this:
1 2 6 7
3 5 8 13
4 9 12 14
10 11 15 16
I have tried some codes to do it myself but i had no success.
View 1 Replies
View Related