C++ :: Control Ofstream Output Field Width?

Apr 25, 2013

I have to output a series of data, I have to control the width of parts of my data. like following:

double a[] = {1.0, 2.0, 3.0};
double b[] = {1.5, 2.5, 3.5};
ofsteam myfile("result.txt");
for(int i=0; i<3; i++) {
myfile.width(5);
myfile << i+1 << " : " << a[i] << " - " << b[i] << end;
}

I only want to fix the width of a[i], b[i], but let the rest to be output normally.

how I can make it?

View 5 Replies


ADVERTISEMENT

C++ :: How To Output One Particular Field In A Form

Aug 8, 2014

I need writing a program in c++ that will get the input of 50 different users for the following the fields (surname, other names, sex, status, date of birth) and after entering the data for these 50 users, it will then output only the list of all FEMALE users who were registered...

#include <iostream>
#include <string>
using namespace std;
int main () {
string surname, other_names1, other_names2, status, sex, dob;

[Code] ....

I don't really know what to do next - all my attempts have not really given me the result I want.

View 19 Replies View Related

C# :: Field Initializer Cannot Reference The Non-static Field / Public Var

Apr 12, 2015

So I have this class

class DataBase
{
// Change the connection path here to your own version of the database
public SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)v11.0;AttachDbFilename=|DataDirectory|UberDatabase.mdf;Integrated Security=True;");
public DataBase()
{
}
}

And in the same namespace as this class I have a form that calls it like so:

DataBase dBase = new DataBase();
SqlCommand trythis = new SqlCommand("Register", dBase.con);

However, I'm getting the field initializer error on dBase.con. I'm not sure why, but when I call the database from another file (program.cs) it works fine this way.

View 8 Replies View Related

Visual C++ :: MFC - FrameWnd Output To Picture Control In Dialog

May 29, 2014

I am working on a MFC application that I used for Image Analysis. I have a FrameWnd called MillChart that I use to generate an Image. This window is displayed at the run time in the application and not a part of the GUI dialog. It automatically resizes according to the different monitor resolutions and because of this there is a lot of empty space to the right of the MillChart. I was planning to add a picture control in the GUI dialog and redirect whatever is displayed in the MillChart to the Picture Control so that I can place my other elements (checkboxes, scrollbars etc) that I use in my app close to this MillChart and also set the size of the MillChart to a constant size.

Here is the code for positioning the elements (Note: I have only shown the MillChart position)

Code:
void CMainFrame::PositionElements()
{
CRect r, r2, r3;
GetClientRect(&r);
int mcs = r.Height() - r2.Height();
mMillChart->MoveWindow(r.right - r2.Width(),r.top + r2.Height(),mcs,mcs);

[Code] .....

View 1 Replies View Related

C++ :: Traffic Control Program - Output Data At Specific Time

Oct 24, 2013

I was given an assignment to create a simple program for traffic control. How should i output data at a specific time, for e.g a driver approaches an intersection, the yellow light will flash indicating that he needs to slow down and then the red light to stop before taking a route. is there any function i can use to output red light a few seconds after yellow light.

View 10 Replies View Related

C# :: Change Form Control Properties From User Control

May 24, 2014

I have researched quite extensively, experimented, and still cannot seem to change the properties of a control on an active winform from a user control.

So I have a user control which populates each dynamically added tab page in a tab control.

I have a textbox in the user control which I would like to type in, capture the text_change event, and change the text of the label in the winform.

View 14 Replies View Related

C# :: Bind DatePicker Control To DataGrid Control (column)?

Apr 25, 2014

How do I bind a DATE column in a DataGridView Control to a DatePicker control (using C#)? I already have the DataGridView control bound to a database stored procedure which takes a DATE value as a parameter and selects joining table based on the results.

View 7 Replies View Related

C++ :: Ofstream In Calling Function

Apr 3, 2013

I am trying to use ofstream to write in a txt file in a function called recurrently. for a simplified example:

void func_write(double x) {
ofstream myfile;
myfile << "the result = " << x << endl;
} int main() {
ofstream myfile;

[Code] .....

To this stage, it does not work, because the myfile in func_write cannot write in the txt file opened in main function. I don't want to open, append and close the txt file each time the function is called, that will take more time to execute all (imagine with 500 calls).

View 2 Replies View Related

C++ :: Getting Error In Ofstream File?

Nov 11, 2014

I am writing an eVoting program the addTally function adds 1 to the Candidate's voting tally when called and prints it back to the file from where it took the input replacing the old text. Now, Why I am getting error when running this program. Whenever i comment out the output file in addTally Function including where its used, it works.

Vote Function

void Vote(vector<int> &id_list, ofstream &voter_list) {
int ID;
bool valid_id;
char choice;
cout << " **** Voting Menu ****

[code]....

Function Adds one to the tally

void addTally(char choice) {
ifstream inCandidate("Candidates.txt");
ofstream outCandidate("Candidates.txt");
string Data_Line;
vector <string> Candidates;
string C_name[5];
int Tally[5];

[code]....

View 5 Replies View Related

C++ :: Ofstream In A Class File?

Apr 22, 2013

so this is part of a larger project but here is a test file that I haven't been able to get running. I don't understand why the minute I put an ofstream object as an instance variable the program flips out.

#include <iostream>
#include "FileNotFoundException.h"
int main() {
using namespace std;
try {
std::cout << "This is a test.";
throw FileNotFoundException("Testing...");

[code]....

View 3 Replies View Related

C++ :: Ofstream Valid Path And Name

Jan 27, 2013

The following code writes to a file on either local disk to a remote disk (commented out code) on Windows 7 platform.

Code:
#include <iostream>
#include <fstream>
using namespace std;
int main () {
ofstream outfile;

[Code].....

The documentation does not specify what is a valid filename (path and filename). For example, will the "\server emp" path work on all operating systems to access a samba share? Does the constructor accept forward and backward slashes as folder separator on all operating systems?

View 1 Replies View Related

C++ :: Adding URL In OfStream To Make VB Script

Jun 21, 2013

So the problem is that if you do launch << " Url = "http://google.com";

That C++ will detect that the second " is the end when really it isn't it is part of the VB script any way around this?

Then the second part that may be screwing this up is the // after the http.

Full code [URL] ....

View 1 Replies View Related

C++ :: Difference Between Ofstream And Ostream Operators

Aug 17, 2014

I'm trying to overload an operator << so that it prints to a .txt file. Would these two codes basically do the same thing? If so, which one is the more efficient one to use?

ofstream& operator<<(ofstream& fout, const Grid& g);

ostream& operator<<(ostream & out, const Grid& g);

View 2 Replies View Related

C++ :: Student Database - Ifstream And Ofstream Operators

Apr 23, 2013

I've been working on a student data base that reads in the students name, birth date, social security, and department name (or major). I have all these items in the header files respectively; nameType, dateType, personType, and studentType.

I am now to create another header file called HWONEHEADER that contains the functions showMenu, loadStudent, insertStudent, searchByName, and SaveStudents. This is how far ive gotten

#ifndef HW
#define HW
#include <iostream>
#include <fstream>
#include <iomanip>
#include "studentType.h"

[Code] .....

Here is the cpp file i have.

int main() {
studentType department;
cin>>department;
cout<<department;

[Code] .....

I need with the HWONEHEADER using the ifstream and ofstream operators to load all the students information into a file called student.dat I'am extremely confused because i can't find anything in my textbook about using ifstream and ofstream operators.

View 3 Replies View Related

C++ ::  OfStream In Vector Failing To Open File

Feb 20, 2015

I'm trying to move a dictionary into a group of bite-sized files based off of the length of the strings in each file (I'm ignoring strings of length 1 for obvious reasons). Since I don't know what the longest word is (and I'm not going to look for it), and I don't want redundant files, I decided to use a vector of output file streams that I would put all the words into, but I can't get the file to open.

I took a look at it and found the failbit is 1, but the badbit is 0, so apparently it's a logic error on opening the stream [URL] .... I looked online and decided to try using pointers, but that didn't work either, so now I'm asking what the problem might be, because I can't think of any reason why it isn't working.

void createDictionary() {
//declare variables
string dictionaryName;//name of dictionary file
ifstream dictionaryIn;//file of original dictionary
vector<shared_ptr<ofstream>> dictionaryOut;//files where dictionary will be put based off of word length
string word;//input from the dictionary file
vector<int> lengths;//vector containing available lengths and their locations
unsigned long long counter = 0;

[Code] ....

View 2 Replies View Related

C++ :: Templated Function Using Ofstream Strange Characters

Nov 5, 2014

To generate output data, I'm printing a bunch of vector contents to files. Because the type of variable can differ between vectors, I wrote a templated printing function to print out whatever the content of the vector is. It looks like this:

template <class T>
void SomeClass::PrintVector(std::vector<T>& Values, std::string& outFile) {
std::ofstream out(outFile, std::ios::app);

[Code] ....

I added the fixed because some larger values were being printed in scientific notation. Everything works well. My test code includes 3 vectors of doubles and 3 vectors of unsigneds. All the unsigneds work well and two of the doubles work well, but the third doubles vector prints nonsense unless I disable the fixed.

The calling code is the exact same. I know the values in the vector are correct, because a) if I comment out the "fixed" flag it works, and b) one of the unsigned vectors is sorted based on the values in that double vector (after it is printed, so the sort cannot corrupt the vector print) and works perfectly.

The "nonsense" looks like chinese/weird characters, if that matters.

View 11 Replies View Related

C++ :: Variable (Width) Is Being Used Without Initialized

Mar 14, 2013

It said my width1 is being used wihtout being initialized.. what does it mean?

#include<iostream>
using namespace std;

double Area(double height, double width);
double Perimeter(double height, double width, double height1, double width1);

[Code] .....

View 2 Replies View Related

C :: Width Specifier Does Not Align Like In Printf

Apr 19, 2013

I am currently debugging this function. I am trying to make this function's width specifier align like a printf() routine. Here 's the code:

v Code:
oid
bu_log(const char *fmt, ...) {
va_list ap;
struct bu_vls output = BU_VLS_INIT_ZERO;

if (UNLIKELY(!fmt || strlen(fmt) == 0)) {
bu_vls_free(&output);

[Code] ....

View 8 Replies View Related

C# :: Width And Height For Column And Rows

Mar 21, 2014

Basically when I type in different widths and heights for the col and rows, the buttons that make up the width get cut off. Something is messed up but I'm not sure what!

InitializeComponent();
int _col = int.Parse(cols);
int _row = int.Parse(rows);
int width = groupBox1.Width;
int height = groupBox1.Height;
int bW = width / _col;
int bH = height / _row;

[Code] ....

View 4 Replies View Related

C# :: Extending The Width Of The Labels To Specific Value?

Jun 3, 2014

The program is when a person clicks a button this button updates 2 separate listbox one tracks the total rolls the other displays the total amounts of frequency afterwards adjusting labels as a scaling measurement.

The problem I am having is right at the end where I am trying to adjust the width of the label this is what I have. It is highlighting the word "Items" for each label and says that Non-Invokable member 'System.Windows.Forms.ListBox.Items' Cannot be used like a method L2 is a label. Additionally I have added in the information for one of my loops below the line I am having trouble with this loop is created to determine how many lines are in the listbox of rolls and I have no trouble with this just thought id add it for additional information I dont think I need to add the rest of the code but I can if needed.

L2.Width = int.Parse(lstfrequency.Items(0).ToString());
TL = 0;
for (I = 0; I <= 10; I++)
{
TL += int.Parse(lstfrequency.Items[I].ToString());
}
lstfrequency.Items.Add(TL);

View 9 Replies View Related

C/C++ :: How To Use Rectangle Height And Width In Functions

May 13, 2014

The problem says:

Define functions n(), s(), e(), w(), center(), ne(), se(), sw() and nw(). Each takes a Rectangle argument and returns a Point. These functions define connection points on and in the rectangle. For example, nw® is the northwest (top-left corner) of a rectangle called r.

I wrote below code for that:

#include <Simple_window.h>
Point n(const Graph_lib::Rectangle& r);
Point s(const Graph_lib::Rectangle& r);
Point e(const Graph_lib::Rectangle& r);
Point w(const Graph_lib::Rectangle& r);
Point ne(const Graph_lib::Rectangle& r);
Point se(const Graph_lib::Rectangle& r);

[Code]...

As you see, this just mark the top-left corner of the rectangle r. In other functions I need the specifications of that rectangle, for example its height and width. How to use these specs in those functions?

View 2 Replies View Related

C Sharp :: Graphic Pen 1 Sided Width?

Apr 28, 2012

I am drawing two circle (inner circle and outer circle) using DrawElipse method. I have created two pen object named OuterPen and InnerPen and creating Outer Circle using OuterPen and Inner Circle using InnerPen. Problem that I am facing is that when I increase the size of outer pen lets say 10px then it overlaps the inner circle and inner circle is hide. How can I increase the size of OuterPen outwards and not inwards so that it don't overlap the inner circle?

View 3 Replies View Related

Visual C++ :: Width And Height From HBITMAP?

Sep 5, 2013

If I get a bitmap from the clipboard with:

hBitmap=(HBITMAP)GetClipboardData(CF_BITMAP);

...how do I get the width and height ? Can I get at the BITMAPINFO ?

View 2 Replies View Related

C :: Getting Correct Float Value Without Having To Write In Width / Precision

Jul 16, 2014

I have this

Code:
#include <stdio.h>
int main() {
float number1, number2;
printf("Enter two numbers separated by a comma ");
scanf("%f,%f", &number1, &number2);

[Code] ....

When it prints the values, it prints them as I want. the problem is, what happens when someone puts in values with different width and precision? Here I had to write in the width and precision to display the values that are specified in the book. but what happens when someone puts in something that doesn't have those width/precision?

I end up with a lot of zeros after the number. initially I got 24.000000 (zeros are not accurate amount) I needed to show just 24. (with the decimal)

So I included %2.0f which gave me 24 (without the decimal point) what if some one put in 24.556. I got 25 as a result.

Does the width mean how many numbers in total including the decimal point and that is a minimum?

View 5 Replies View Related

C++ :: Print Out Square Of Stars With Different Length And Width Given?

Feb 27, 2013

#include <iostream>
using namespace std;
int main()
{

[Code].....

how do i change this code to accept two numbers from the user and print it as the different length and widtth? it has to be a for loop as well.[code]

View 5 Replies View Related

C++ :: Set Width Of Data Values Which User Will Input

Sep 24, 2014

I am trying to set the width of the data values which the user will input when using the program but I don't know how to get it to show the values when I tryto set the width of the variables in a nice column .

//Programming Assignment 4

#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
using namespace std;
int main() {
double q1r1, q2r1, q3r1, q4r1;
double q1r2, q2r2, q3r2, q4r2;
double q1r3, q2r3, q3r3, q4r3;

[Code] ....

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved