Strig to Char? – C / C++ – Fórum – Programujte.com
 x   TIP: Přetáhni ikonu na hlavní panel pro připnutí webu

Strig to Char? – C / C++ – Fórum – Programujte.comStrig to Char? – C / C++ – Fórum – Programujte.com

 

exim
~ Anonymní uživatel
37 příspěvků
23. 6. 2010   #1
-
0
-

Zdravim, mám VS a v něm aplikaci kde je kalendář, při změně data se udělá událost a vybrané datum se uloží do proměné string.

Dále potřebuju otevřít soubor s názvem xx.xx.xxxx.txt kde xxxx... je hodnota vybraného datumu, ale bohužel on to chce v charu já už nevím jak to převýst... Díky za rady...

	private: System::Void monthCalendar1_DateChanged(System::Object^  sender, System::Windows::Forms::DateRangeEventArgs^  e) {

System::String ^ vyber = this->monthCalendar1->SelectionStart.ToString(L"d");
this->label2->Text = vyber;




fstream file(vyber+".txt");

file.close();



}



Chyba:
1>c:\users\exilim\documents\visual studio 2008\projects\kalendar\kalendar\Form1.h(154) : error C2664: 'std::basic_fstream<_Elem,_Traits>::basic_fstream(const char *,std::ios_base::openmode,int)' : cannot convert parameter 1 from 'System::String ^' to 'const char *'

1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> No user-defined-conversion operator available, or
1> Cannot convert a managed type to an unmanaged type



Díky

Nahlásit jako SPAM
IP: 195.113.159.–
liborb
~ Redaktor
+18
Guru
23. 6. 2010   #2
-
0
-
Nahlásit jako SPAM
IP: 85.207.166.–
exim
~ Anonymní uživatel
37 příspěvků
23. 6. 2010   #3
-
0
-

Bohužel, ani jedno mi nejde

Nahlásit jako SPAM
IP: 195.113.159.–
KIIV
~ Moderátor
+43
God of flame
23. 6. 2010   #4
-
0
-

to nejde ani ( (vyber+".txt").c_str() ); ?

Nahlásit jako SPAM
IP: 62.168.56.–
Program vždy dělá to co naprogramujete, ne to co chcete...
liborb
~ Redaktor
+18
Guru
23. 6. 2010   #5
-
0
-

Takže třeba tohle ti nefunguje?:



System::String ^ vyber = this->monthCalendar1->SelectionStart.ToString(L"d");

this->label2->Text = vyber;

vyber = vyber + ".txt";

const char* pszFileName = (char*)(void*)Marshal::StringToHGlobalAnsi(vyber);

fstream file(pszFileName);

Marshal::FreeHGlobal((System::IntPtr)(void*)pszFileName);

file.close();

Nahlásit jako SPAM
IP: 85.207.166.–
exim
~ Anonymní uživatel
37 příspěvků
24. 6. 2010   #6
-
0
-

1>d:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\atlconv.h(90) : error C3641: 'InterlockedExchangePointer' : invalid calling convention '__stdcall ' for function compiled with /clr:pure or /clr:safe

1>d:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\atlconv.h(102) : error C3641: 'ATL::_AtlGetConversionACP' : invalid calling convention '__stdcall ' for function compiled with /clr:pure or /clr:safe
1>d:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\atlconv.h(535) : error C3641: 'AtlA2WHelper' : invalid calling convention '__stdcall ' for function compiled with /clr:pure or /clr:safe
1>d:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\atlconv.h(554) : error C3641: 'AtlW2AHelper' : invalid calling convention '__stdcall ' for function compiled with /clr:pure or /clr:safe
1>d:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\atlconv.h(572) : error C3641: 'AtlA2WHelper' : invalid calling convention '__stdcall ' for function compiled with /clr:pure or /clr:safe
1>d:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\atlconv.h(577) : error C3641: 'AtlW2AHelper' : invalid calling convention '__stdcall ' for function compiled with /clr:pure or /clr:safe
1>d:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\atlconv.h(530) : error C3641: 'AtlDevModeW2A' : invalid calling convention '__stdcall ' for function compiled with /clr:pure or /clr:safe
1>d:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\atltrace.h(65) : error C2440: 'default argument' : cannot convert from 'int (__cdecl *)(int,const char *,int,const char *,const char *,...)' to 'ATL::CTrace::fnCrtDbgReport_t'
1> Address of a function yields __clrcall calling convention in /clr:pure and /clr:safe; consider using __clrcall in target type
1>d:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\atltrace.h(146) : fatal error C1903: unable to recover from previous error(s); stopping compilation

Nahlásit jako SPAM
IP: 195.113.159.–
liborb
~ Redaktor
+18
Guru
24. 6. 2010   #7
-
0
-

Tak zkus změnit v nastavení projektu volbu Common Language Runtime Support na hodnotu Common Language Runtime Support (/clr).

Nahlásit jako SPAM
IP: 85.207.166.–
exim
~ Anonymní uživatel
37 příspěvků
24. 6. 2010   #8
-
0
-

pod čím to najdu?

Nahlásit jako SPAM
IP: 195.113.159.–
liborb
~ Redaktor
+18
Guru
24. 6. 2010   #9
-
0
-

Project -> Properties -> General

Nahlásit jako SPAM
IP: 85.207.166.–
exim
~ Anonymní uživatel
37 příspěvků
24. 6. 2010   #10
-
0
-

1>c:\users\exilim\documents\visual studio 2008\projects\kalendar\kalendar\Form1.h(15) : error C2871: 'System' : a namespace with this name does not exist
1>c:\users\exilim\documents\visual studio 2008\projects\kalendar\kalendar\Form1.h(16) : error C2653: 'System' : is not a class or namespace name
1>c:\users\exilim\documents\visual studio 2008\projects\kalendar\kalendar\Form1.h(16) : error C2871: 'ComponentModel' : a namespace with this name does not exist
1>c:\users\exilim\documents\visual studio 2008\projects\kalendar\kalendar\Form1.h(17) : error C2653: 'System' : is not a class or namespace name
1>c:\users\exilim\documents\visual studio 2008\projects\kalendar\kalendar\Form1.h(17) : error C2871: 'Collections' : a namespace with this name does not exist
1>c:\users\exilim\documents\visual studio 2008\projects\kalendar\kalendar\Form1.h(18) : error C2653: 'System' : is not a class or namespace name
1>c:\users\exilim\documents\visual studio 2008\projects\kalendar\kalendar\Form1.h(18) : error C2871: 'Forms' : a namespace with this name does not exist
1>c:\users\exilim\documents\visual studio 2008\projects\kalendar\kalendar\Form1.h(19) : error C2653: 'System' : is not a class or namespace name
1>c:\users\exilim\documents\visual studio 2008\projects\kalendar\kalendar\Form1.h(19) : error C2871: 'Data' : a namespace with this name does not exist
1>c:\users\exilim\documents\visual studio 2008\projects\kalendar\kalendar\Form1.h(20) : error C2653: 'System' : is not a class or namespace name
1>c:\users\exilim\documents\visual studio 2008\projects\kalendar\kalendar\Form1.h(20) : error C2871: 'Drawing' : a namespace with this name does not exist
1>c:\users\exilim\documents\visual studio 2008\projects\kalendar\kalendar\Form1.h(22) : error C2653: 'System' : is not a class or namespace name
1>c:\users\exilim\documents\visual studio 2008\projects\kalendar\kalendar\Form1.h(22) : error C2871: 'Ports' : a namespace with this name does not exist
1>c:\users\exilim\documents\visual studio 2008\projects\kalendar\kalendar\Form1.h(23) : error C2653: 'System' : is not a class or namespace name
1>c:\users\exilim\documents\visual studio 2008\projects\kalendar\kalendar\Form1.h(23) : error C2871: 'InteropServices' : a namespace with this name does not exist
1>c:\users\exilim\documents\visual studio 2008\projects\kalendar\kalendar\Form1.h(25) : error C2653: 'System' : is not a class or namespace name
1>c:\users\exilim\documents\visual studio 2008\projects\kalendar\kalendar\Form1.h(25) : error C2871: 'Text' : a namespace with this name does not exist
1>c:\users\exilim\documents\visual studio 2008\projects\kalendar\kalendar\Form1.h(36) : error C2059: syntax error : 'public'
1>c:\users\exilim\documents\visual studio 2008\projects\kalendar\kalendar\Form1.h(36) : error C2059: syntax error : 'public'
1>c:\users\exilim\documents\visual studio 2008\projects\kalendar\kalendar\Form1.h(36) : error C2653: 'System' : is not a class or namespace name
1>c:\users\exilim\documents\visual studio 2008\projects\kalendar\kalendar\Form1.h(37) : error C2143: syntax error : missing ';' before '{'
1>c:\users\exilim\documents\visual studio 2008\projects\kalendar\kalendar\Form1.h(37) : error C2447: '{' : missing function header (old-style formal list?)
1>.\kalendar.cpp(8) : error C2337: 'STAThreadAttribute' : attribute not found
1>.\kalendar.cpp(9) : error C2065: 'array' : undeclared identifier
1>.\kalendar.cpp(9) : error C2653: 'System' : is not a class or namespace name
1>.\kalendar.cpp(9) : error C2065: 'String' : undeclared identifier
1>.\kalendar.cpp(9) : error C2059: syntax error : '>'
1>.\kalendar.cpp(10) : error C2143: syntax error : missing ';' before '{'
1>.\kalendar.cpp(10) : error C2447: '{' : missing function header (old-style formal list?)
1>AssemblyInfo.cpp
1>.\AssemblyInfo.cpp(3) : error C2871: 'System' : a namespace with this name does not exist
1>.\AssemblyInfo.cpp(4) : error C2653: 'System' : is not a class or namespace name
1>.\AssemblyInfo.cpp(4) : error C2871: 'Reflection' : a namespace with this name does not exist
1>.\AssemblyInfo.cpp(5) : error C2653: 'System' : is not a class or namespace name
1>.\AssemblyInfo.cpp(5) : error C2871: 'CompilerServices' : a namespace with this name does not exist
1>.\AssemblyInfo.cpp(6) : error C2653: 'System' : is not a class or namespace name
1>.\AssemblyInfo.cpp(6) : error C2871: 'InteropServices' : a namespace with this name does not exist
1>.\AssemblyInfo.cpp(7) : error C2653: 'System' : is not a class or namespace name
1>.\AssemblyInfo.cpp(7) : error C2871: 'Permissions' : a namespace with this name does not exist
1>.\AssemblyInfo.cpp(14) : error C2337: 'AssemblyTitleAttribute' : attribute not found
1>.\AssemblyInfo.cpp(15) : error C2337: 'AssemblyDescriptionAttribute' : attribute not found
1>.\AssemblyInfo.cpp(16) : error C2337: 'AssemblyConfigurationAttribute' : attribute not found
1>.\AssemblyInfo.cpp(17) : error C2337: 'AssemblyCompanyAttribute' : attribute not found
1>.\AssemblyInfo.cpp(18) : error C2337: 'AssemblyProductAttribute' : attribute not found
1>.\AssemblyInfo.cpp(19) : error C2337: 'AssemblyCopyrightAttribute' : attribute not found
1>.\AssemblyInfo.cpp(20) : error C2337: 'AssemblyTrademarkAttribute' : attribute not found
1>.\AssemblyInfo.cpp(21) : error C2337: 'AssemblyCultureAttribute' : attribute not found
1>.\AssemblyInfo.cpp(34) : error C2337: 'AssemblyVersionAttribute' : attribute not found
1>.\AssemblyInfo.cpp(36) : error C2337: 'ComVisible' : attribute not found
1>.\AssemblyInfo.cpp(38) : error C2337: 'CLSCompliantAttribute' : attribute not found
1>.\AssemblyInfo.cpp(40) : error C2337: 'SecurityPermission' : attribute not found
1>.\AssemblyInfo.cpp(40) : error C2653: 'SecurityAction' : is not a class or namespace name
1>.\AssemblyInfo.cpp(40) : error C2065: 'RequestMinimum' : undeclared identifier
1> missing quotes ("") around 'RequestMinimum'?

Nahlásit jako SPAM
IP: 82.113.52.–
liborb
~ Redaktor
+18
Guru
25. 6. 2010   #11
-
0
-

No ... máš tam chyby ... a hodně .... možná bude lepší, když sem šoupneš kompletní projekt

Nahlásit jako SPAM
IP: 85.207.166.–
exim
~ Anonymní uživatel
37 příspěvků
25. 6. 2010   #12
-
0
-

Příloha

Nahlásit jako SPAM
IP: 195.113.159.–
liborb
~ Redaktor
+18
Guru
25. 6. 2010   #13
-
0
-

Chybí ti tam na začátku použité namespace. Musíš tam přidat všechny, které používáš, tj. něco jako:



using namespace System;
using namespace System::ComponentModel;
using namespace System::Windows::Forms;
using namespace System::Runtime::InteropServices;

// a vsechny dalsi, co pouzivas viz nejlépe msdn

Nahlásit jako SPAM
IP: 85.207.166.–
exim
~ Anonymní uživatel
37 příspěvků
25. 6. 2010   #14
-
0
-

je tam zakomentovany

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;

using namespace System::IO::Ports;
using namespace System::Runtime::InteropServices;
using namespace std;
using namespace System::Text;


ale tu hlasku kterpu sem sem dal bylo s nezakomentovanym namespacem

Nahlásit jako SPAM
IP: 195.113.159.–
liborb
~ Redaktor
+18
Guru
25. 6. 2010   #15
-
0
-

Aha ... pravda, je to tam, ale spíš to očekával nějak takto:



#pragma once

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;

using namespace System::IO::Ports;
using namespace System::Runtime::InteropServices;
using namespace std;
using namespace System::Text;

#include <windows.h>
#include <string>
#include "stdafx.h"
#include <iostream>
#include <sstream>
#include <string>
#include <fstream> // souborové I/O
#include <iomanip> // další manipulace s formátem
#include <atlstr.h> // for class CString

namespace kalendar {

// ...... atd.

Nahlásit jako SPAM
IP: 85.207.166.–
exim
~ Anonymní uživatel
37 příspěvků
25. 6. 2010   #16
-
0
-

nepomohlo :(

Nahlásit jako SPAM
IP: 82.113.52.–
liborb
~ Redaktor
+18
Guru
25. 6. 2010   #17
-
0
-

Těžko radit, když není dost informací. Třeba někdo bude vědět, ale lepší by to bylo s celým projektem.

Nahlásit jako SPAM
IP: 91.203.96.–
exim
~ Anonymní uživatel
37 příspěvků
26. 6. 2010   #18
-
0
-

tak tady je project

Nahlásit jako SPAM
IP: 82.113.52.–
liborb
~ Redaktor
+18
Guru
29. 6. 2010   #19
-
0
-

Problém je v tom, že mixuješ C++ přístup a C++/CLI přístup. Jestlit o chceš dělat v C++/CLI, tak musíš v projektu nastavit podporu
Common Language Runtime Support (/clr), jak jsem psal výše. Dále vyhodit všechny #include a std, protože je nepotřebuješ a kolidují ti. A jako poslední věc místo fstream použít k tomu určenou třídu http://www.functionx.com/cppcli/fileprocessing/Lesson01c.htm.

Nahlásit jako SPAM
IP: 85.207.166.–
JKlena
~ Anonymní uživatel
4 příspěvky
6. 7. 2010   #20
-
0
-

Sem sice len začátečník, ale nešlo by to string pretvorit na jednotlive chary nejak takto:

string text = "2010"
char prveCislo = ConverTo.Char(text[0]);
char druheCislo = ConvertTo.Char(text[1]);
.....a zbyle 2

a nechat to teda zapisovat jak char?

Nahlásit jako SPAM
IP: 78.99.189.–
exim
~ Anonymní uživatel
37 příspěvků
6. 7. 2010   #21
-
0
-

Libor prosím mužeš si mě přidat na icq nebo skype? 338617070 / kubik_23 díky

Nahlásit jako SPAM
IP: 82.113.52.–
liborb
~ Redaktor
+18
Guru
7. 7. 2010   #22
-
0
-

To exim : To nemůžu, protože nemám. Ani jedna z těchto obzvláště vypečených služeb mi nepřirostla k srdci, takže jedině Jabber, email nebo soukromá pošta tady na fóru (viz moje kontaktní údaje).

Nahlásit jako SPAM
IP: 85.207.166.–
Zjistit počet nových příspěvků

Přidej příspěvek

Toto téma je starší jak čtvrt roku – přidej svůj příspěvek jen tehdy, máš-li k tématu opravdu co říct!

Ano, opravdu chci reagovat → zobrazí formulář pro přidání příspěvku

×Vložení zdrojáku

×Vložení obrázku

Vložit URL obrázku Vybrat obrázek na disku
Vlož URL adresu obrázku:
Klikni a vyber obrázek z počítače:

×Vložení videa

Aktuálně jsou podporována videa ze serverů YouTube, Vimeo a Dailymotion.
×
 
Podporujeme Gravatara.
Zadej URL adresu Avatara (40 x 40 px) nebo emailovou adresu pro použití Gravatara.
Email nikam neukládáme, po získání Gravatara je zahozen.
-
Pravidla pro psaní příspěvků, používej diakritiku. ENTER pro nový odstavec, SHIFT + ENTER pro nový řádek.
Sledovat nové příspěvky (pouze pro přihlášené)
Sleduj vlákno a v případě přidání nového příspěvku o tom budeš vědět mezi prvními.
Reaguješ na příspěvek:

Uživatelé prohlížející si toto vlákno

Uživatelé on-line: 0 registrovaných, 6 hostů

Podobná vlákna

CHAR — založil Jeyekomon

Char vo for — založil Rastislav Cupa

C++ char — založil 3ker

String to char — založil kadet

Problem s char* — založil Tom9k

Moderátoři diskuze

 

Hostujeme u Českého hostingu       ISSN 1801-1586       ⇡ Nahoru Webtea.cz logo © 20032024 Programujte.com
Zasadilo a pěstuje Webtea.cz, šéfredaktor Lukáš Churý