Error C2664 Fstream
Contents |
here for a quick overview of the site Help Center Detailed answers to open file based on user input c++ any questions you might have Meta Discuss the workings and
Prompt User To Enter File Name C++
policies of this site About Us Learn more about Stack Overflow the company Business Learn c++ c_str more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow
Open File C++
Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up I'm getting error C2664 on some I/O code up vote 2 down vote favorite void BinaryTree::InitializeFromFile(string Filename){ ifstream inFile; inFile.open(Filename, fstream::binary); if(inFile.fail()){ cout<<"Error in opening file ifstream "<
the beginning there are problems compiling it. 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
1 1>Compiling... 1>livc++.cpp 1>.\livc++.cpp(13) : error C2664: 'void std::basic_ifstream<_Elem,_Traits>::open(const http://www.cplusplus.com/forum/beginner/6590/ wchar_t *,std::ios_base::openmode,int)' : cannot convert parameter 1 from 'std::string' to 'const wchar_t *' 1> with 1> [ 1> _Elem=char, 1> _Traits=std::char_traits
first time posting here so I'm sorry if I post something wrong. I have an assignment for my class and I think I have done everything right, well except for this one error that's been killing me. I get this error for https://www.daniweb.com/programming/software-development/threads/330279/error-c2664-cannot-convert-parameter-1 each function call when I try to compile (so basically two errors) (109): error C2664: https://www.gidforums.com/t-10586.html 'sortArray' : cannot convert parameter 1 from 'std::string *' to 'char *[]' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast (113): error C2664: 'binarySearch' : cannot convert parameter 1 from 'std::string *' to 'char *[]' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast I had this error before with doubles and the open file way I fixed it was to remove the pointers in the array, now whenever I do that it gives me about 10 more errors, basically about std:operators or something, and I need the stuff to be in a string for my homework assignment. Use C-Strings to do Part 1 of the assignment and the string class to do Part 2 of the assignment. Part 2 of this Assignment requires your program to read in a list of error c2664 fstream strings from a file called strings3.dat, then display, sort, display, and search the strings (just like Assignment #1 but with strings, not integers). Use the string class to do Part 2 of the assignment (do not use C-Strings to store the strings read from strings3.dat). Here's my code so far #include
Thread #1 08-Jul-2006, 10:03 jdbrine Junior Member Join Date: May 2006 Posts: 56 ofstream Problem I am getting a compile error when trying to use the ofstream object. I've used it before and don't understand why I'm receiving the error. At this point in my program, I'm just trying to set up my FileWriter class and test it. Code and error is below: //FileWriter.h CPP / C++ / C Code:
#ifndef _FILEWRITER_H #define _FILEWRITER_H #include//FileWriter.cpp CPP / C++ / C Code:#include using namespace std; class FileWriter { private: ofstream fileout; bool ready; public: FileWriter(); //FileWriter(fileout); void Write(string s); void WriteLn (string s); void Write(int n); void WriteLn (int n); void NewLine(); bool isReady(); void OpenFile(); void setPrecision(int n); void OpenFile(string f); //~FileWriter(); }; #endif
#include#include #include "FileWriter.h" using namespace std; FileWriter::FileWriter() { ready=false; std::string strFile; strFile="Test.txt"; fileout.open(strFile.c_str, ios_base::out ); /*error C2664: 'void __thiscall std::basic_ofstream >::open(const char *,int)' : cannot convert parameter 1 from 'const char *(void) const' to 'const char *' There is no context in which this conversion is possible*/ } /*FileWriter::FileWriter(fileout) { }*/ void FileWriter::Write(string s) { } void FileWriter::Write(int n) { } void FileWriter::WriteLn(string s) { } voi