Error 1 Error C2446
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn 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 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 error C2446: == : no conversion from const char * to TCHAR * up vote 1 down vote favorite I have a TCHAR define below: TCHAR szProcessName[MAX_PATH] = TEXT(""); and I want to comapare as below: if(szProcessName == "NDSClient.exe") { } But then I am getting the errors: error C2446: == : no conversion from const char * to TCHAR * error C2440: '==' : cannot convert from 'const char [14]' to 'TCHAR [260]' c++ windows tchar share|improve this question asked Nov 17 '10 at 6:00 Simsons 3,4581882160 add a comment| 2 Answers 2 active oldest votes up vote 7 down vote accepted "NDSClient.exe" is a const char* string on windows. If you want it to become a const TCHAR* then you need to use the TEXT macro. Also, you can not compare strings using == use a equivalent TCHAR function such as _tcscmp. share|improve this answer answered Nov 17 '10 at 6:04 Naveen 43.9k34116205 add a comment| up vote 5 down vote Also you can use. L"some string" to make TCHAR*. But I suggest you to use std::wstring (analog of std::string and as std::string needs #include ) instead of TCHAR*. example: #include #include #include using namespace std; int main() { wstring s = TEXT("HELLO"); wstring ss = L"HELLO"; if(s == ss) cout << "hello" << endl; return 0; } share|improve this answer edited Nov 20 '10 at 16:22 Armen Tsirunyan 76.4k32215343 answered Nov 17 '10 at 8:41 Mihran Hovsepyan 5,79693788 Fixed your code tags for you. –graham.reeds Nov 17 '10 at 8:42 L"some string" is a WCHAR* not a TCHAR*. –MSalters Nov 17 '10 at 9:13 If you're using std::wstring then you should just use wchar_t everywhere instead of TCHAR. (And by extension you shouldn't use the TEXT macro) –Billy ONeal Nov 17 '10 at 14:30 Also do note that L"some string" is not a WCHAR*. It is const WCHAR[12] :) –Armen Tsirunyan Nov 20 '10 at 16:24 Thanks to all of you for usefull comments. It was very helpfull for me. –Mihran Hovsepyan
why? Page 1 of 1 New Topic/Question Reply 13 Replies - 9042 Views - Last Post: 30 June 2009 - 12:21 PM Rate Topic: #1 Pipey85 New D.I.C Head Reputation: 0 Posts: 41 Joined: 30-June 09 error c2446 and error c2040 (beginner) Posted 30 June 2009 - 11:05 AM OK, ive only been doing c++ programming for about 2 weeks, after watching many tutorial videos, and this is my 1st attempt at defining/declaring functions, and using the switch statement, but i keep getting these two error messages..... error C2446: '==' : no conversion from 'const char *' to 'int' 1> There is no context in which this conversion is possible and error C2040: '==' : 'int' differs in levels http://stackoverflow.com/questions/4201893/error-c2446-no-conversion-from-const-char-to-tchar of indirection from 'const char [4]' they both refer to the if statement that is pointed out. EDIT: i have no idea how well the program will actually work so please dont spoil it for me #include "stdafx.h" #include using namespace std; int multiply (int num1, int num2); int divide (int num1, int num2); int subtract (int num1, int num2); int add(int num1, int num2); int main() { bool start = true; int num1; int num2; char http://www.dreamincode.net/forums/topic/112515-error-c2446-and-error-c2040-beginner/ strt; int op; while (start == true) cout << "System ready\n" << "Please give 1st of two numbers\n"; cin >> num1; cout << "Please give 2nd number\n"; cin >> num2; cout << "What would you like to do with these numbers?\n1.Add\n2.subtract\n3.multiply\n4.divide"; cin >> op; switch (op) { case 1: { add (num1, num2); break; } case 2: { subtract (num1, num2); break; } case 3: { multiply (num1, num2); break; } case 4: { divide (num1, num2); break; } default: { cout << "\nPROGRAM ERROR!!!"; start = true; } } cout << "\nWould you like to start again?"; cin >> strt; if (strt == 'y' || strt == 'Y' || strt == "yes") //This line here is what seems to be giving me start = true; // trouble else start = false; return 0; } int multiply (int num1, int num2) { int result; result = num1 * num2; return result; } int divide (int num1, int num2) { int result; result = num1 / num2; return result; } int subtract (int num1, int num2) { int result; result = num1 - num2; return result; } int add(int no1, int no2) { int rsult = no1 + no2; return rsult; } please note, i know there are 'cleaner' ways to make a simple calculator, but this is to try and understand the switch statement and the calling functions, thanx guys. Thi
make sure that http://www.cyberforum.ru/cpp-beginners/thread642941.html the spelling is correct.Note: Most addresses are case sensitive. For information on IBM offerings, start from the IBM homepage. For information on printing systems, start from the Infoprint Solutions error 1 Company homepage.* For information on ThinkPad notebooks, ThinkCentre desktops and other PC products, start from the Lenovo homepage.* Search the IBM Web site. Get assistance This option lets you send an information request and tell us error 1 error about a broken link. You will receive an e-mail from us to help you find what you need. Requested uid value cannot be empty * Links notated by a grey asterisk (*) will take you to web sites for the following companies that sell former IBM products. Printing systems are now products of InfoPrint Solutions Company. ThinkPad notebooks, ThinkCentre™ desktops and other PC products are now products of Lenovo. Self-help resources Locate your IBM Easy Access site Support & downloads Site availability Site assistance Contact and feedback Need support? Submit feedback to IBM Support 1-800-IBM-7378 (USA) Directory of worldwide contacts Contact Privacy Terms of use Accessibility
Пароль Восстановить пароль Регистрация Регистрация Тесты Блоги Сообщество Поиск Ссылки сообщества Социальные группы Поиск Google по форуму Поиск Yandex по форуму Поиск по форуму Расширенный поиск Тесты Список тестов К странице... @ch_perch 0 / 0 / 0 Регистрация: 20.11.2011 Сообщений: 11 27.08.2012, 13:40 Ошибка error C2446: '==' : no conversion from 'const char *' to 'int' #1 C++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 #include using namespace std; int main () { int a,b; char op; int res; cout << "write constant and sing"; cin >> a; cin >> b; cin >> op; if (op == "+") res = a+b; else if (op == "-") res = a-b; else if (op == "/") res = a/b; else if (op == "*") res = a*b; else cout << "bad operetion!"; return 0; }Так получилось что решил посмотреть видео урок. Это скопированный код из него. Компилирую, выдает выше описанную ошибку. Подскажите пожалуйста что не так? Similar Эксперт 41792 / 34177 / 6122 Регистрация: 12.04.2006 Сообщений: 57,940 27.08.2012, 13:40 Ошибка error C2446: '==' : no conversion from 'const char *' to 'int' Посмотрите здесь: Invalid conversion from 'const char*' to 'char' C++ C++ Invalid conversion from `int' to `const char*'Ошибка С2446 no conversion from 'const char *' to '_TCHAR *' C++ Несовместимость типов данных: Error:invalid conversion from 'int' to 'const char*' C++ C++ [Ошибка] invalid conversion from 'const char*' to 'char*' [-fpermissive] После регистрации реклама в сообщениях будет скрыта и будут доступны все возможности форума. @Gibboustooth 733 / 201 / 10 Регистрация: 23.06.2011 Сообщений: 440 27.08.2012, 13:42 Ошибка error C2446: '==' : no conversion from 'const char *' to 'int' #2 Для символов используются одинарные кавычки. Двойные - для строк. @DaskOFF 112 / 112 / 9 Регистрация: 02.05.2012 Сообщений: 521 Записей в блоге: 1 27.08.2012, 13:42 Ошибка error C2446: '==' : no conversion from 'const char *' to