a string problem

January 24, 2010 at 03:03:14
Specs: Windows XP
I'm having difficulties witha C++ program.Plese look at it...I'm reading from a file...and I want to make a function where I can read from the file calling a string.In the main program the string will be initialised with the file's name.aannddaa_92
#include<cstdlib>
#include<iostream>
#include<fstream>
#include<string>

using namespace std;

int n,a[50][50];
char nume_fisier[50];

int citire(string nume_fisier)
{
fstream f;
int i,j;

f.open(nume_fisier,ios::in);
f>>n;
for (i=1;i<=n;i=i+1)
{
for (j=1;j<=n;j=j+1)

{
a[i][j]=0;
}
}

while(!f.eof())
{
f>>i;
f>>j;
a[i][j]=1;
a[j][i]=1;
}
f.close();
return (n);
}

void afisare(int n);
{
int i,j;
for (i=1;i<=n;i=i+1)
{
for (j=1;j<=n;j=j+1)
{
cout<<a[i][j]<<" ";
}
cout<<" "<<"\n";
}

int main ()
{
citire("graf.txt");
afisare(n);
cin>>x;
return 0;
};



See More: a string problem

Report •

#1
January 24, 2010 at 16:49:28
The first parameter of stream.open(...) is a const char * and not a string class member. To use your string object, try nume_fisier.c_str() or use a char array

HTH


Report •
Related Solutions


Ask Question