Hello,
I have writen a C++ program to read 37 text files. The content of the text file is interger numbers. The program was working fine in VC++ 6.0. Now i could not find the free version of VC++ 6.0. I downloaded the free version of VC++ 2008 expression edition and run the same code which was working fine in the older version.
Now it could not read the input file and there is no error while compiling the program. The name of the text files are b1.txt, b2.txt.... b37.txt.
Please help me to fix the problem. I have given below the code for your reference.

#include<process.h>
#include "stdafx.h"
#include<new.h>
#include<conio.h>
#include<dos.h>
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
#include <vector>
typedef std::vector<int> IntArray1D;
typedef std::vector<IntArray1D> IntArray2D;
typedef std::vector<float> FloatArray1D;
typedef std::vector<FloatArray1D> FloatArray2D;
using namespace std;

ofstream fout;

std::vector<vector<int> > a;      //variable to access the input matriz
int m,n;    char outstr[10];
int nclus;float bz;
class memory
{

    public:
    void mci_memory();

};
void memory::mci_memory()
{
    int i;
    //memory allocation for input values
    a.resize(m);
    for ( i =0; i < m; ++i )
    a[i].resize( n );
void main()
{
    int i,j;
    char str1[10];          //to read the first input file
    char str2[10]={".txt"};
    char str3[15];          //to read the second input file
    char aq[10];

    for(who=1;who<=37;who++)
    {
        ifstream fin;
        //Reading of input file one
        strcpy(str1,"b");
        strcat(str1,_i64toa(who,aq,10));
        strcat(str1,str2);
        fin.open(str1); //opening of input file and reading the condents
        fin>>nclus;
        fin>>m;
        fin>>n;
        memo.mci_memory();
        for(i=0;i<m;i++)
        {
             for(j=0;j<n;j++)
             {
                 fin>>a[i][j];

             }
             cout<<endl;
        }
        fin.close();


}

There were a lot of compiler changes between the two versions that you are using -- 6.0 and 2008. One of the changes is that 2008 uses UNICODE strings by default. You can begin to analyze your problem by turning off UNICODE. Go to menu Project --> Properties (at the bottom of the list), expand Configuration Properties tab, select General. Then on the right side of the screen, third item from the bottom change "Character Set" to "Not Set".

There are several improvements I could suggest to your program, but I suppose you just want it to work for now, so I won't mention them.

Hi
Thank you for your answer, i did the same change that you have mentioned. Still, i have the same issue. I badly need to fix the issue.
I saved the input files in the directory where i have created my C++ project.
It would be more help for me, if you could suggest to improve my code. I have given only the portion of my code. If you help me, i can apply it to my entire code.

Note that main() always returns int, never ever void.

#include <fstream>
#include <iostream>
#include <string>
#include <sstream>

int main()
{
    for(int who = 1; who < 37; who++)
    {
       std::stringstream str;
       str << "b" << who << ".txt";
       ifstream in(str.str());
       // etc. etc.
    }
}

Thank you so much for your information.. still the problem exists. i have given below the data in the input text file b1.txt.

2
5 7
0 1 0 1 1 1 0
1 0 1 0 0 0 0
1 0 1 0 0 1 1
0 1 0 1 0 1 0
1 0 0 0 1 0 1


can you please run the code and help me out. I am working on this code for more than 4 days....
Thank you

you mean this? I don't know why your program is trying to read 37 files, so I'll just kind of ignore that minor detail and hopefull you can figure out how to do it from the code I am posting below.

#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>

void display(std::vector< std::vector<int> >& arry)
{
    for(size_t i = 0; i < arry.size(); i++)
    {
        std::vector<int>& cols = arry[i];
        for(size_t j = 0; j < cols.size(); j++)
            std::cout << cols[j] << ' ';
        std::cout << '\n';
    }

}

int main()
{
    std::vector< std::vector<int> > arry;
    for(int who = 1; who < 37; who++)
    {
       std::stringstream str;
       str << "b" << who << ".txt";
       std::ifstream in(str.str());
       if( in.is_open() )
       {
           int nclus, m, n;
           in >> nclus >> m >> n;
           std::vector<int> cols(n, 0);
           for(int i = 0; i < m; i++)
           {
               for(int j = 0; j < n; j++)
               {
                   in >> cols[j];
               }
               arry.push_back(cols);
           }
           in.close();
           in.clear();
       }
    }
    display(arry);
}

Thank you so much for your help. I have writed the program to read each input files and two functions. One function is to calculate a output value to each input data based on mathematical formulae. The other function is to manimulate the data in the input file and create output files (text files) to each input file.

I copied yout code and executed it. I had the following error.

1>------ Build started: Project: acoresult, Configuration: Debug Win32 ------
1>Compiling...
1>checkresult.cpp
1>d:\megala\acoresult\acoresult\checkresult.cpp(26) : error C2664: 'std::basic_ifstream<_Elem,_Traits>::basic_ifstream(const char *,std::ios_base::openmode,int)' : cannot convert parameter 1 from 'std::basic_string<_Elem,_Traits,_Ax>' to 'const char *'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>Build log was saved at "file://d:\megala\acoresult\acoresult\Debug\BuildLog.htm"
1>acoresult - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Please help me to resolve the issue. I am willing to send you the complete code and input files, if you could help m

Use str.str().c_str() instead of str.str() on line 26. You need the std::string value represented as a C-style string ( char * ) and the c_str() method gets you that.

Thank for your reply. Now the code is working fine. Thank you very much to Anciant dragon and Jonsca

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.