|
Without further info it is hard to tell what kind of problem you've run into. Even so, I might risk the following: are you using cout or std::cout (same for cin )? It is the latter that you should be using.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
Want a Boost forum in Code Project? Vote here[^]!
|
|
|
|
|
By using the std namespace you make the program managed (at least I think so). I need a pure C++ program, without any .NET elements.
|
|
|
|
|
By using the std namespace you make the program managed (at least I think so).
No no, the std namespace has nothing to do with managed/unmanaged code. You can use it. Believe me
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
Want a Boost forum in Code Project? Vote here[^]!
|
|
|
|
|
Thanks.
|
|
|
|
|
Hi
I have Visual C++ 6.0
I want to move the left side of Horz ScrollBar some pixels to the right in an MDIChild window in an application with split bar with two rows and one column.
How can I accomplish this ?
Thanks
Manosza.
|
|
|
|
|
hello,
i was wondering which set of functions to use to store user preferences in the registry. is there an example on the web of how best to do this?
thanks,
edward herskovits
Edward H Herskovits
Noetic Systems Incorporated
www.noeticsystems.com
"When certainty is not enough."
|
|
|
|
|
If you're using MFC, I think the best ones to use are the methods of your CWinApp class, like WriteProfileString() ,WriteProfileInt() , and WriteProfileBinary() . And use the respective Get***() functions to get the info back from the registry.
while(true)
{
TryToLearn("C++,MFC");
}
My articles[^]
www.stillwaterexpress.com
bdiamond
|
|
|
|
|
ehh wrote:
is there an example on the web of how best to do this?
How about here?
"Opinions are neither right nor wrong. I cannot change your opinion of me. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Even if you get your hands on a registry access class (and there are several on this website), keep this in mind:
1. If you want the setting ot be a PROGRMA WIDE setting, then youc an place it into HKEY_LOCAL_MAHCINE, but most users will onyl have READ access to the values.
2. If you want it to be a per-user setting, then you can read and write to the HKEY_CURRENT_USER
3. If you want new users to inherit some default settings, then user HKEY_USERS\.Default as the base key to write the information.
|
|
|
|
|
Thanks to all who responded; I have a much better idea of how to implement user preferences now.
Thanks!
Edward H Herskovits
Noetic Systems Incorporated
www.noeticsystems.com
"When certainty is not enough."
|
|
|
|
|
could someone help me code this. I've tried everyway i know how.
1. You will simulate a memory bank of a computer using an array.
1. The program will read in an input file that represents a series of commands to the system to start and stop of different programs.
2. Each program will have an identification number (int) and a memory size (int)
3. Your program will search the array representing the computer's memory for the smallest available space in memory large enough for the program being called and reserve those array locations for the program being started.
4. When an end program call is made the program's memory is released.
5. If enough memory is not currently available, the program will go on a waiting list until such time as enough memory is available in one location or until it is cancelled.
6. The waiting list gives higher priority to programs started first.
7. Your memory array will be of a fixed size of 2048 units.
8. For the purposes of this lab the waiting list can be implemented as an array of length 50.
9. Output each action taken to the screen (program starting, stopping, entering or leaving the waiting list).
|
|
|
|
|
Izaquad wrote:
I've tried everyway i know how.
And those ways would be how?
"Opinions are neither right nor wrong. I cannot change your opinion of me. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
//void MemLocation(int beginEnd[][3]);
int main()
{
// declaring variables.
int memArray[2048] = {0};
string action;
int progID, memSize, memBegin, memEnd = -1;
int waitArray[50] = {0};
string fileName;
int arrVal =0;
// prompting user to enter file name for input
cout << "Please enter name of file to read." <<endl;
cin="">> fileName;
// declaring and opeing input
ifstream inFile ("lab8data.txt");//fileName.c_str());
cout << endl;
while (!inFile)
{
inFile.clear();
cout << "File, " << fileName << ", not found! Please re-enter." << endl;
cin >> fileName;
inFile.open (fileName.c_str());
}
while(!inFile.eof())
{
inFile >> action;
if(action == "Start")
{
if(arrVal < 2048)
{
inFile >> progID >> memSize;
cout << "Starting program: " << progID << endl;
arrVal += 1;
}
else
{
inFile >>progID;
cout << "Program "<< progID << " is entering waiting list."<
|
|
|
|
|
Ok, so what works? What doesn't work? Have you stepped through the code line-by-line? What does the lab8data.txt file look like?
"Opinions are neither right nor wrong. I cannot change your opinion of me. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Start 1 1000
Start 2 500
Stop 2
Start 3 1200
Start 4 2000
Stop 1
Start 5 750
Start 6 200
Stop 5
Stop 3
Stop 6
Stop 4
Start 7 100
Start 8 500
Start 9 50
Start 10 1500
Start 11 450
Start 12 500
Start 13 100
Start 14 500
Stop 14
Stop 7
Stop 10
Stop 11
Stop 9
Stop 8
Stop 13
Stop 12
|
|
|
|
|
i suggest you pay to some one to help you complete the long school project.
includeh10
|
|
|
|
|
Whatever you're doing:
1. Find a good/free/available debugger and learn how to use it. You'll save time. As David Crow suggested step through what you have and see if it works. What values the variables have etc.
2. Plan your program. I remember my projects, and I'd write them off the top of my head. You'll do much better to lay out and draw some stuff. For example you know you'll need a parser for the file. That's one block. You'll need something to manage your queue (add/remove items from it). That's another block. You'll need a way to keep track of what range of memory is taken and what isn't.
|
|
|
|
|
Hello there!
I figured this site would be a perfect place to ask about my problem (I came here because I was searching for a solutiong on Google).
Anyways, here's my problem. I use Visual Studio NET 2003 to write C/C++ projects. The nature of my assignments requires me to limit the length of the code lines by 80 character, because the code is printed out often and this is how our printers are set up. In other editors that I used before, there was a way to display the vertical dashed line so many characters away from the left margin, or to physically limit the width of the edit page. In VC NET however, I couldn't find any such option, and thus it gets on my nerves constantly having to pay attention to the length of each line of code that I write
It would be amazing if I found a way to limit the Edit Window width (kind of like in MS Word) rather than having it stretched to the right infinitely. There's a selection margin on the left side of the Edit Window (where the line numbers are), would be great if a similar margin was on the right hand side too, with the actual text area in between being 80 character wide.
I don't know much about windows api, I work on unrelated projects, but I'm sure that it would take a few minutes to code this for someone who knows what he's doing.
I would greatly appreciate if someone wrote this add-in for me (or pointed me to an existing one).
|
|
|
|
|
I think the best way to go about this (and easiest) would be to write a VBScript macro in your macrose IDE. I don't know very much about the syntax, but I've written a few of my own macros by looking at existing ones (the samples that come with VS). I would write the macro so that it loops through each line, and if it's longer than 80 characters, reversefind the first space and issue a linebreak and maybe a tab character or something like that that would let you know that it was continued from the previous line, or maybe something like /*cont...*/ on the following line before the actual text.
while(true)
{
TryToLearn("C++,MFC");
}
My articles[^]
www.stillwaterexpress.com
bdiamond
|
|
|
|
|
Look for a pretty printer on google. There are a number of programs designed to make your programs nice to look at. (I think I saw someone use one built into visual C once, but since I've never used it I don't know)
|
|
|
|
|
First. I appreciate that you spend your time to read my question.
I have question about how to define an object array at private area.
For example: I have a class which is call base_class; I want to create a new class which is called
new_class; But I want to define base_class[50] in my new class. Could someone help me?
When I am compiler my main program, I got following message.
"studentDB.h type name expected "
But I didn't get any wrong message when I was compiler both student.cpp and studentDB.cpp files.
The following code is what I write in my program;
//This is my main program--------------------------------------------
#include <iostream>
#include <fstream>
#include <string>
#include "studentDB.h"
using namespace std;
int main()
{
string filename[2]; //declare an array to save a input filename and a output filename;
cout << "Enter input file name: ";
cin >> filename[0];
cout << "Enter output file name: ";
cin >> filename[1];
student_db database; //create a class
if(database.read_data(filename[0],filename[1]))
{
cout << "Data for " << database.how_many_record() << " students was read into the database…\n";
bool should_I_leave=false;
char command; //The variable will save the command that user choose.
string temp_info[4];
int temp_age;
while(!should_I_leave) //When user type Q or q will leave loop.
{
cout << "Enter command (A -> add, R -> remove, D -> display, S -> show all, Q -> quit): ";
cin >> command;
switch (command)
{
case 'A': case 'a':
cout << "Enter social security number: ";
cin >> temp_info[0];
cout << "Enter last name: ";
cin >> temp_info[1];
cout << "Enter first name: ";
cin >> temp_info[2];
cout << "Enter age: ";
cin >> temp_age;
cout << "Enter phone: ";
cin >> temp_info[3];
if(database.add_Student(temp_info[0],temp_info[1],temp_info[2],temp_age,temp_info[3]))
cout << "Student added!\n";
else
cout << "Student with ssn: " << temp_info[0] << " already exist!\n";
break;
case 'D': case 'd':
cout << "Enter ssn of student to display: ";
cin >> temp_info[0];
database.display_Student(temp_info[0]);
break;
case 'R': case 'r':
cout << "Enter ssn of student to display: ";
cin >> temp_info[0];
if(database.delete_Student(temp_info[0]))
cout << "Student deleted!\n";
else
cout << "Student with ssn: " << temp_info[0] << " NOT found!\n";
break;
case 'S': case 's':
database.display_all();
break;
case 'Q': case 'q':
database.write_result();
should_I_leave=true;
break;
}
}
}
else
{
cout << "the name of the file does not exist\n";
}
return 0;
}
// I define the function of the student_db here.----------------------------------
//filename: studentDB.cpp
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
#include "student.h"
#include "studentDB.h"
using namespace std;
// The function will return a value that showing how many records in database.
int student_db::how_many_record()
{
return how_many_in_database;
}
// add a student to the database – return true if successful, false otherwise
bool student_db::add_Student(string ssn, string lastname, string firstname, int age, string phone)
{
if(searchSSN(ssn)==-1) //if the SSN cann't find in the array, saving a new record to the array.
{
student_collect[how_many_in_database].set_ssn(ssn);
student_collect[how_many_in_database].set_lastname(lastname);
student_collect[how_many_in_database].set_firstname(firstname);
student_collect[how_many_in_database].set_age(age);
student_collect[how_many_in_database].set_phone(phone);
how_many_in_database++; //We add 1 to count after we add one person to the array.
SortBySSN();// The function will write out a table of students sorted by social security number (in ascending order)
return true;
}
else
return false;
}
//The function will call searchSSN function to search a data and searchSSN function will return a index.
// delete student with a particular social security number – return true if successful
// and false otherwise
bool student_db::delete_Student(string ssn)
{
int check=0;
check=searchSSN(ssn);
if(check!=-1) //if the index number is not -1, the program will start remove a record.
{
swap(check,how_many_in_database-1);
how_many_in_database--;
SortBySSN();
return true;
}
else
return false;
}
// display the data for student if present in the database – otherwise error message
void student_db::display_Student(string ssn)
{
int check=0;
check=searchSSN(ssn);
if(check!=-1)
{
cout << "\tStudent Data: \n";
cout << "\t\tSSN: " << student_collect[check].show_ssn() << endl;
cout << "\t\tLast Name: " << student_collect[check].show_lastname() << endl;
cout << "\t\tFirst Name: " << student_collect[check].show_firstname() << endl;
cout << "\t\tPhone Number: " << student_collect[check].show_phone() << endl;
cout << "\t\tAge: " << student_collect[check].show_age() << endl;
}
else
cout << "Student with ssn: " << ssn << " NOT found\n";
}
// display data for ALL the student in the database
void student_db::display_all()
{
cout << setw(10) << "Last Name" << setw(10) << "First Name" << setw(16) << "SSN" << setw(18) << "Phone Number" << setw(7) << "Age" << endl;
for(int i=0;i<how_many_in_database;i++)
{
cout << setw(10) << student_collect[i].show_lastname() << setw(10) << student_collect[i].show_firstname() << setw(16) << student_collect[i].show_ssn() << setw(18) << student_collect[i].show_phone() << setw(7) << student_collect[i].show_age() << endl;
}
cout << endl;
}
student_db::student_db()
{
max_people_in_database=50; //How many people do you have?
}
student_db::~student_db()
{
Savefile.close();
Openfile.close();
}
// The function will write out a table of students sorted by SSN or Last Name.
//The parameter that is called datanumber will tell the fuction how many loop does it need.
void student_db::write_result()
{
Savefile << endl;
for(int i=0;i<how_many_in_database;i++)
{
Savefile << setw(10) << student_collect[i].show_lastname() << setw(10) << student_collect[i].show_firstname() << setw(16) << student_collect[i].show_ssn() << setw(18) << student_collect[i].show_phone() << setw(7) << student_collect[i].show_age() << endl;
}
Savefile << endl;
}
//The function that use binary search algorithm will return -1 if it can not find same SSN in the array or return index if it find the SSN.
//The first parameter tell the function SSN that the function need to check.
//The second parameter tell the function how many loop it should do.
int student_db::searchSSN(string ssn)
{
int returnvalue=0;
if(ssn==student_collect[how_many_in_database/2-1].show_ssn())
{
returnvalue=how_many_in_database/2-1;
}
else if( ssn > student_collect[how_many_in_database/2-1].show_ssn())
{
for(int i=how_many_in_database/2; i<how_many_in_database;i++)
{
if(ssn==student_collect[i].show_ssn())
{
returnvalue=i;
i=how_many_in_database; //finding the value, leaving loop
}
else
returnvalue=-1;
}
}
else
{
for( int i=0;i < how_many_in_database/2 ; i++)
{
if(ssn==student_collect[i].show_ssn())
{
returnvalue=i;
i=how_many_in_database; //finding the value, leaving loop
}
else
returnvalue=-1;
}
}
return returnvalue;
}
// The function will exchange the content of these two parameters
void student_db::swap(int i,int j)
{
student temp;
temp=student_collect[i];
student_collect[i]=student_collect[j];
student_collect[j]=temp;
}
// The function will save students sorted by social security number (in ascending order).
// The parameter that is called datanumber will tell the fuction how many loop does it need.
void student_db::SortBySSN()
{
for(int i=0;i<how_many_in_database;i++)
{
for(int j=i+1;j<how_many_in_database;j++)
{
if(student_collect[i].show_ssn() > student_collect[j].show_ssn())
swap(i,j);
}
}
}
// read data from disk - return true if data exist, false otherwise.
bool student_db::read_data(string in_filename, string out_filename)
{
Openfile.open(in_filename.c_str());
if(Openfile==NULL) //IF FILE DOES NOT EXIST, finish the function.
{
return false;
}
else // executing this scope if the file exist
{
Savefile.open(out_filename.c_str());
input_filename=in_filename; //recording a name of the inputfile to filename[0]
output_filename=out_filename; //recording a name of the outputfile to filename[1]
string temp_use; //the variable will save a string that read from inputfile for temp.
int temp_int_use; //the variable will save a integer that read from inputfile for temp.
for(int i=0;i<max_people_in_database;i++) //reading data to database
{
if(Openfile==NULL) //leaving for loop if there is nothing in the file.
break;
Openfile >> temp_use;
student_collect[i].set_lastname(temp_use);
Openfile >> temp_use;
student_collect[i].set_firstname(temp_use);
Openfile >> temp_use;
student_collect[i].set_ssn(temp_use);
Openfile >> temp_use;
student_collect[i].set_phone(temp_use);
Openfile >> temp_int_use;
student_collect[i].set_age(temp_int_use);
how_many_in_database=i; //the variable will record how many data in database.
}
SortBySSN();
return true;
}
}
// This is my new class.
//filename: studentDB.h
class student_db
{
public:
// add a student to the database – return true if successful, false otherwise
bool add_Student(std::string , std::string , std::string , int , std::string);
// delete student with a particular social security number – return true if successful
// and false otherwise
bool delete_Student(std::string);
// display the data for student if present in the database – otherwise error message
void display_Student(std::string);
// display data for ALL the student in the database
void display_all();
// read data from disk - return true if data exist, false otherwise.
bool read_data(std::string,std::string);
// The function will write out a table of students sorted by SSN or Last Name.
void write_result();
// The function will return a value that showing how many records in database.
int how_many_record();
student_db();
~student_db();
private:
// The function will save students sorted by social security number (in ascending order).
// The parameter that is called datanumber will tell the fuction how many loop does it need.
void SortBySSN();
// The function will exchange the content of these two parameters
void swap(int,int);
//The function that use binary search algorithm will return -1 if it can not find same SSN in the array or return index if it find the SSN.
//The first parameter tell the function SSN that the function need to check.
//The second parameter tell the function how many loop it should do.
int searchSSN(std::string);
std::ifstream Openfile;
std::ofstream Savefile;
int how_many_in_database; //recording how many data in the database.
int max_people_in_database;
std::string input_filename; //input_filename record the inputfile name.
std::string output_filename; //output_filename record the outfilename;
student student_collect[50]; //You can change your max number of the people here.
};
//I define the function of the student class here.----------------------------------------------
//filename:student.cpp
#include <iostream>
#include "student.h"
//--------------------------------------------------------------------------------
// The following functions declare for the class of student.
//--------------------------------------------------------------------------------
std::string student::show_lastname()
{
return lastname;
}
std::string student::show_firstname()
{
return firstname;
}
std::string student::show_ssn()
{
return ssn;
}
int student::show_age()
{
return age;
}
std::string student::show_phone()
{
return phone;
}
void student::set_lastname(std::string text)
{
lastname=text;
}
void student::set_firstname(std::string text)
{
firstname=text;
}
void student::set_ssn(std::string text)
{
ssn=text;
}
void student::set_age(int number)
{
age=number;
}
void student::set_phone(std::string text)
{
phone=text;
}
// student class is my basic class------------------------------------------
//filename:student.h
class student
{
public:
void set_lastname(std::string );
void set_firstname(std::string );
void set_ssn(std::string );
void set_age(int);
void set_phone(std::string );
std::string show_lastname();
std::string show_firstname();
std::string show_ssn();
int show_age();
std::string show_phone();
private:
std::string lastname;
std::string firstname;
std::string ssn;
int age;
std::string phone;
};
|
|
|
|
|
This line in studentDB.h
student student_collect[50];
is using student without this type being defined first. Just #include "student.h" at studentDB.h and at least your first problem should go away (I haven't compiled any further.)
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
Want a Boost forum in Code Project? Vote here[^]!
|
|
|
|
|
Thank you help. It work.
Bless you.
|
|
|
|
|
Hi All,
I am trying to generate a binary image from a normal image and obtain it as a matrice. Could anyone teach me how can it be made? I knew that in matlab, it is possible to do it within a few lines. But how can I do that in VC++?
thanks!
Jason
|
|
|
|
|
This will taken more than a few lines.
First you'll need an interface, define how to open images, how to display them etc. The MFC Doc/View project created with the wizard will give you a skeleton where you can fill in the code for the opening/displaying. But you'll have to figure out how to use it.
To load the actual image into memory you will need a library that will decode the image from some format (jpeg, bitmap, gif etc) and give you the pixels. There are many libraries that do that. You can try
http://www.codeproject.com/bitmap/cximage.asp[^]
You can also see the demo code and modify it. The page also lists other libraries.
The conversion to binary image you'll probably have to do yourself. That should be easy once you have the pixels to the loaded image.
|
|
|
|