Don’t Erase Contents of Text File

Category: C++ Questions    |    0 views    |    Add a Comment
Hi, It’s me again with another silly question:)
I was wondering if there was a way using ofstream to not erase the contents of the file it is writing to and simply write at the end.
Thanks!
P.S. I’m using windows XP and Dev C++

Share/Save/Bookmark

 

songa rating prog

Category: C++ Questions    |    0 views    |    Add a Comment
#include<iostream.h>
#include<conio.h>
void main()
{
int n,i,j,t,s;
clrscr();
char sname[30],rating[60];
cout<<"enter no of songs in the list"<<endl;
cin>>n;
cout<<"enter song name and rating"<<endl;
for(i=1;i<=n;i++)
{
cin>>sname[i];
}
for(i=1;i<=n;i++)
{
cin>>rating[i];
}
cout<<"The top songs are in the order:"<<endl;
for(i=1;i<=n;i++)
{
for(j=i+1;j<=n;j++)
{
if(rating[i]<rating[j])
{
t=rating[i];
s=sname[i];
rating[i]= rating[j];
sname[i]=sname[j];
rating[j]=t;
sname[j]=s;
}
}
}
for(i=1;i<=n;i++)
{

cout<<"Name:"<<sname[i]<<"rating:"<<rating[i]<<endl;
}

getch();
}

I am a beginner in C++ n am tryin to write a prog which gets the songs name n rating as input and list the songs with greater rating in the ascending, the problem is i could input oly one character as ip for song name and i am not aware of a soln,so geeks pls help n i welcome improvisations too:)

Share/Save/Bookmark

 

why does it compile but not run?

Category: C++ Questions    |    0 views    |    Add a Comment
Using Dev-cpp, a small program compiles but the resultant .exe file
does not run. From the DOS command, it runs. When I try from the
windows run command , it flashes but immediately goes away.

Share/Save/Bookmark

 

A class example not running

Category: C++ Questions    |    0 views    |    Add a Comment
//cube.h

#ifndef CUBE_H
#define CUBE_H

class Cube
{
public:
Cube();
~Cube();
void setSide(double s);
double getSide();
double Area();
double Volume();
void Properties();
private:
double Side;
};

#endif
´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´
#include <iostream>
#include "cube.h"
using namespace std;
Cube::Cube()
{
}

Cube::~Cube()
{
}

void Cube::setSide(double s)
{
Side = s <= 0 ? 1 : s;
}

double Cube::getSide()
{
return Side;
}

double Cube::Area()
{
return 6 * Side * Side;
}

double Cube::Volume()
{
return Side * Side * Side;
}

void Cube::Properties()
{
cout << "Characteristics of this cube";
cout << "\nSide = " << getSide();
cout << "\nArea = " << Area();
cout << "\nVolume = " << Volume() << "\n\n";
}
´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´

//main.cpp
#include "cube.h"
using namespace std;
int main()
{
Cube cube;
cube.setSide(-12.55);
cube.Properties();

Cube de;
de.setSide(28.15);
de.Properties();

return 0;
}

´´´´´´´´´´´´´´´´´´´´´´´
compiling with g++ main.cpp -0 main

Share/Save/Bookmark