473,770 Members | 4,544 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Couldn't understand what my error means

31 New Member
I got this error:

error C2664: 'Vector::setVec tor' : cannot convert parameter 1 from 'const std::ifstream' to 'std::ifstream'

How can it not be able to convert from std::ifstream to std::ifstream?? ?

Here's the relevant code (I didn't put all the variables as those are not relevant):

header file:
class Matrix{

public:
.
.
.
.

void setMatrix(ifstr eam txtFile);

};

void Matrix::setMatr ix (ifstream txtFile) {
int x;

for (int i = 0; i < this->rowLength; i++) {
for (int j = 0; j < this->columnLength ; j++) {
txtFile >> x;
this->contents[i][j] = x;
}
}
}

cpp file:

void main() {
string txtFileName;

Matrix matrix1;

cout << "Enter name of vector/matrix file (use a txt file): ";
cin >> txtFileName;

ifstream txtFile(txtFile Name.c_str());


matrix1.setMatr ix (txtFile); //error occurs here
}
Sep 18 '07 #1
21 2562
blackx
31 New Member
I posted the wrong error code, here's the relevant error code:

error C2664: 'Matrix::setMat rix' : cannot convert parameter 1 from 'std::ifstream' to 'std::ifstream'
No copy constructor available for class 'std::basic_ifs tream<_Elem,_Tr aits>' or constructor attempts to perform illegal conversion to non-__gc reference
with
[
_Elem=char,
_Traits=std::ch ar_traits<char>
]
Sep 18 '07 #2
Savage
1,764 Recognized Expert Top Contributor
Have you tryed passing it with reference:

void Matrix::setMatr ix(const ifstream &txtFile);

??
PS:Please use code tags(#button)
Savage
Sep 18 '07 #3
blackx
31 New Member
thanks for replying,

if I pass by reference,

in main();

should i use:

matrix1.setMatr ix (txtFile); //there's no compile error here but the values returned are memory addresses, not the actual values

or

matrix1.setMatr ix (&txtFile); //this gives a compile error

error C2664: 'Matrix::setMat rix' : cannot convert parameter 1 from 'std::ifstream *__w64 ' to 'std::ifstream &'
Sep 18 '07 #4
Savage
1,764 Recognized Expert Top Contributor
thanks for replying,

if I pass by reference,

in main();

should i use:

matrix1.setMatr ix (txtFile); //there's no compile error here but the values returned are memory addresses, not the actual values

or

matrix1.setMatr ix (&txtFile); //this gives a compile error

error C2664: 'Matrix::setMat rix' : cannot convert parameter 1 from 'std::ifstream *__w64 ' to 'std::ifstream &'
There is no difference in function call when your function takes a pass by reference and pass by value.The problem is somewhere else.

How did you found that return values are memory addresses?

Savage
Sep 18 '07 #5
blackx
31 New Member
using

matrix1.setMatr ix (txtFile);

I run the code and got like -85988360 as values in my matrix (must be memory addresses)

any suggestions on how to fix my code?
Sep 18 '07 #6
Savage
1,764 Recognized Expert Top Contributor
using

matrix1.setMatr ix (txtFile);

I run the code and got like -85988360 as values in my matrix (must be memory addresses)

any suggestions on how to fix my code?
Try couting x from inside the setMatrix() function.

Savage
Sep 18 '07 #7
blackx
31 New Member
I actually have a different function, printMatrix() that does the cout. But I will try to include the cout inside the setMatrix function and see what I get.
Sep 18 '07 #8
Savage
1,764 Recognized Expert Top Contributor
I actually have a different function, printMatrix() that does the cout. But I will try to include the cout inside the setMatrix function and see what I get.
It's only for debug purposes.

Savage
Sep 18 '07 #9
blackx
31 New Member
okay something is definitely wrong with my code, I tried 2 different methods of reading.

the txt file reads:

1.0 2.0 3.6 4.0

1 2 3 4
2 3 4 5
3 4 5 6
4 5 6 7

1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1

but when I run the code (with the cout inside the setVector and setMatrix functions), I got
Vector:
1.0000 1.0000 1.0000 1.0000

Matrix:
1.0000 1.0000 1.0000 1.0000
1.0000 1.0000 1.0000 1.0000
1.0000 1.0000 1.0000 1.0000
1.0000 1.0000 1.0000 1.0000

Here's the code for the function:

method 1
Expand|Select|Wrap|Line Numbers
  1. void Vector::setVector (string txtFileName) {
  2.     int x;
  3.  
  4.     ifstream txtFile(txtFileName.c_str());
  5.  
  6.     for (int i = 0; i < this->length; i++) {
  7.         txtFile >> x;
  8.         this->contents[i] = x;            
  9.     }
  10.  
  11.     int numberWidth = 8;
  12.     int decimalPlaces = 4;
  13.  
  14.     for (int i = 0; i < this->length; i++) {
  15.         cout.width(numberWidth); 
  16.         cout << fixed << setprecision(decimalPlaces) << this->contents[i];
  17.         cout << '\t';
  18.     }
  19.  
  20.     cout << endl;
method 2:
Expand|Select|Wrap|Line Numbers
  1. void Matrix::setMatrix (ifstream &txtFile) {
  2.     int x;
  3.  
  4.     for (int i = 0; i < this->rowLength; i++) {
  5.         for (int j = 0; j < this->columnLength; j++) {
  6.             txtFile >> x;
  7.             this->contents[i][j] = x;            
  8.         }
  9.     }
  10.  
  11.     int numberWidth = 8;
  12.     int decimalPlaces = 4;
  13.  
  14.     for (int i = 0; i < this->rowLength; i++) {
  15.         for (int j = 0; j < this->columnLength;  j++) {
  16.             cout.width(numberWidth); 
  17.             cout << fixed << setprecision(decimalPlaces) << this->contents[i][j];
  18.             cout << '\t';
  19.         }
  20.         cout << endl; 
  21.     }
  22.  
  23.     cout << endl;
  24. }
  25.  
Sep 18 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

14
7907
by: william | last post by:
Hi, I could run hello.htm, but hello.asp. They are same except the file name. ..... <body> hello. </body> ..... I set Execute Permission to Script or Excutable(windows 2000, IIS5.0) from Home directory of IIS property. Any idea?
0
1843
by: QWERTY | last post by:
--------------Boundary-00=_O5I3QL80000000000000 Content-Type: Multipart/Alternative; boundary="------------Boundary-00=_O5I3LVC0000000000000" --------------Boundary-00=_O5I3LVC0000000000000 Content-Type: Text/Plain; charset="iso-8859-9" Content-Transfer-Encoding: quoted-printable
10
2304
by: forgotten field | last post by:
Hi,how are you? I have been studying C++ by myself, but recently I am having a real problem. I am learning about the basic usage of a doubly linked list using polymorphism. However, I have got the compiler errors which I just can't understand what they mean. I searched the webs for any clues on how to solve the problems. But I've never been able to find one. Now I am wondering if there is any website which tells people how to understand...
18
4611
by: __frank__ | last post by:
The following code use a macro and a label. I would to change it and use instead a more readable function and avoid the label. The macro DAQmxFailed checks for the return code of the various functions: DAQmxCreateTask() DAQmxStartTask() DAQmxReadAnalogScalarF64()
2
2151
by: Murthy | last post by:
Hi, After genarating the exe when i run the exe the following error is comming. Common Language Runtime Debugging Services Application has generated an exception that could not be handled. Process id=0xdec (3564), Thread id=0xdf0 (3568) When I click CANCEL to debug, I get this error-message:
1
2475
by: ganesah | last post by:
recently i'd downloaded a source code in c++ and tried to compile and run in VS C++ 6.0. however the source code couldn't be compiled. the error is as follows> before that, there is a header file in the source code written like this #include "..\..\..\VspApi\VspApi.h" and the error message is as follows: the include file couldnt be opened '..\..\..\VspApi\VspApi.h' : file or directory couldn be found... what should i modify here to...
8
1863
by: Joshua Moore | last post by:
/* Hi, I was hoping someone could help me with this problem. I did my work and worked my way through the usual compiler messages, but I have run against some problem I can't identify. The compiler error message is unintelligable -- to me anyway. Anyway: Here is the code, maybe someone can tell me what is wrong with it. */ //buysome.cpp //Joshua Moore //the part responsible for the buying part of the farm pos simulation program
0
1573
by: Rajgodfather | last post by:
I am getting the end couldn't error while validating xml file against xsd. The xml file looks perfect. XML: <event id="1"> <!-- Successful event. --> <AffectedBillingComponentsRequest
0
1806
by: akshaycjoshi | last post by:
I am reading a book which says Even though unboxed value types don't have a type object pointer, you can still call virtual methods (such as Equals, GetHashCode, or ToString) inherited or overridden by the type. The reason is because the CLR can just call these methods nonvirtually and System.ValueType overrides all of these virtual methods and expects the value in the this argument to refer to an unboxed value type instance. Remember, a...
0
9591
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9425
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10053
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7415
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6676
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5312
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5449
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3969
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.