Search code, repositories, users, issues, pull requests…
Provide feedback
Saved searches
Use saved searches to filter your results more quickly
Sign up
|
soa432 0 / 0 / 0 Регистрация: 09.12.2012 Сообщений: 18 |
||||
|
1 |
||||
|
03.02.2013, 02:47. Показов 3825. Ответов 1 Метки нет (Все метки)
Не могу понять в чем ошибка, все из-за того что поменял компилятор, старый работал нормально, никаких ошибок не выдавал. Сейчас VS 2012
0 |
|
MrGluck Форумчанин 8215 / 5045 / 1437 Регистрация: 29.11.2010 Сообщений: 13,453 |
||||
|
03.02.2013, 03:09 |
2 |
|||
warning т.к. в int записывался std::size_t (unsigned), соответственно могла быть ошибка при преобразовании.
1 |
for (int v = 0; v <= WordChosen.length();v++)
{
if(Letter == WordChosen[v])
{
WordChosenDuplicate.replace(v,1,Letter);
}
}
I get this error
«Error 4 error C2664:
‘std::basic_string<_Elem,_Traits,_Ax>
&std::basic_string<_Elem,_Traits,_Ax>::replace(__w64
unsigned int,__w64 unsigned int,const
std::basic_string<_Elem,_Traits,_Ax>
&)’ : cannot convert parameter 3 from
‘char’ to ‘const
std::basic_string<_Elem,_Traits,_Ax>
&’ c:\documents and settings\main\my
documents\uni\2nd
year\tp2\hangman\hangman\hangman.cpp 147
«
I only got the error after putting this line in
WordChosenDuplicate.replace(v,1,Letter);
asked Apr 16, 2009 at 11:34
0
Or
WordChosenDuplicate.replace(v,1,std::string(Letter, 1));
answered Apr 16, 2009 at 11:41
Mykola GolubyevMykola Golubyev
58k15 gold badges89 silver badges102 bronze badges
The std::string::replace() function’s parameters are incorrect or you need to invoke a different overload of replace. Something like:
WordChosenDuplicate.replace(v, // substring begining at index v
1, // of length 1
1, // replace by 1 copy of
Letter); // character Letter
answered Apr 16, 2009 at 11:40
dirkgentlydirkgently
108k16 gold badges132 silver badges187 bronze badges
What do you want to achieve? The version of replace that you are trying to call doesn’t exist – as the compiler is telling you. Which of these versions do you mean?
answered Apr 16, 2009 at 11:36
Konrad RudolphKonrad Rudolph
531k133 gold badges939 silver badges1214 bronze badges
2
It appears that WordChosenDuplicate is a std::string, in which case the 3rd parameter in the replace() method should be another std::string or a c-style const char*. You are trying to pass a single char instead («Letter»). The error is saying that there is no version of replace() that takes a char as the 3rd parameter.
answered Apr 16, 2009 at 11:41
PowerApp101PowerApp101
1,7981 gold badge18 silver badges25 bronze badges

Иногда можно встретить вопросы об странных ошибках, выдаваемых компилятором при сборке 64-битного кода.
Вопрос может выглядеть следующим образом:
//Объявление класса
class Type1 {...};
class Type2 {...};
class A
{
public:
...
void Func1(Type1* t1.....);
void Func1(Type2& t2.....);
...
};
//Использование функции Func1
A obj;
Type2 t2;
...
obj.Func1(t2,...);
...
Данный код успешно компилировался в 32-битном режиме, но при попытке собрать 64-битную версию компилятор выдает ошибку C2664 (не может привести Type2 к Type1*). Определена функция, которая принимает Type2& в качестве аргумента, но компилятор почему-то пытается подставить функцию, принимающую Type1* в качестве параметра. В чем может быть проблема?
Скорее всего, дело в других параметрах, которые в примере были заменены точками. Рассмотрим следующий код:
class Type1 {};
class Type2 {};
class A
{
public:
void Func1(Type1* t1, unsigned &);
void Func1(Type2& t2, size_t &);
};
void use() {
A obj;
Type2 t2;
unsigned u;
obj.Func1(t2, u);
}
Он успешно компилируется в 32-битном режиме. Но в 64-битном обе функции не подходят. Компилятор принимает решение, что первая функция является лучшим кандидатом, так как у нее точно совпадает второй параметр. И сообщает, что не подходит первый аргумент: error C2664: ‘void A::Func1(Type1 *,unsigned int &)’ : cannot convert parameter 1 from ‘Type2’ to ‘Type1 *’. Решение — внимательно изучить остальные аргументы и внести в код необходимые изменния.
Присылаем лучшие статьи раз в месяц
Учу WinApi, задали написать файловый менеджер.
#include "pch.h"
#include <iostream>
#include <windows.h>
#include <string>
#include <fstream>
using namespace std;
int main()
{
HANDLE hFindFile, hFile;
WIN32_FIND_DATA fd, file_inf[100];
int i, counter;
counter = 0;
string comand, directory, prev, file_name, user_path, addition[100];
directory = "D:\\";
prev = "D:\\";
bool x = true;
i = 0;
while (true) {
cout << "help to see all comands" << endl;
cin >> comand;
if (comand == "help") {
cout << "dir - show all files in current directory" << endl;
cout << "cd - enter directory" << endl;
cout << "kill - delete file" << endl;
cout << "text - create file" << endl;
cout << "copy - copy file" << endl;
}
if (comand == "dir") {
cout << "_____________" << endl;
hFindFile = FindFirstFile ((directory + "*.*").c_str(), &fd);
file_inf[0] = fd;
while (FindNextFile(hFindFile, &fd)) {
i++;
file_inf[i] = fd;
}
int n = i;
for (i = 0; i <= n - 1; i++) {
cout << file_inf[i].cFileName << endl;
}
cout << "_____________" << endl;
i = 0;
}
if (comand == "cd") {
cout << "directory name?" << endl;
cin >> addition[counter];
if (addition[counter] == "..") {
counter--;
directory = prev;
}
else {
counter++;
}
for (int i = 0; i < counter; i++) {
directory += "\\" + addition[i] + "\\";
}
cout << directory << endl;
}
if (comand == "kill") {
cout << "file's name?" << endl;
cin >> file_name;
hFindFile = FindFirstFile((directory + file_name + "*.*").c_str(), &fd);
file_inf[0] = fd;
cout << directory + file_name << endl;
DeleteFile((directory + file_inf[0].cFileName).c_str());
}
if (comand == "create") {
cout << "file's name?" << endl;
cin >> file_name;
hFile = CreateFile((directory + file_name).c_str(),
GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
CloseHandle(hFile);
}
if (comand == "copy") {
cout << "file's name?" << endl;
cin >> file_name;
cout << "new folder?" << endl;
cin >> user_path;
CopyFile((directory + file_name).c_str(), (user_path + file_name).c_str(), false);
}
}
system("pause");
return 0;
}
Выдает 4 ошибки по типу: C2664 «HANDLE FindFirstFileW(LPCWSTR,LPWIN32_FIND_DATAW)»: невозможно преобразовать аргумент 1 из «const _Elem *» в «LPCWSTR». Подскажите как быть?
