come cavolo si fa ?
es,ho una:
string str = "123";
int k;
voglio fare in modo che k abbia il il valore 123.
come cavolo si fa ?
es,ho una:
string str = "123";
int k;
voglio fare in modo che k abbia il il valore 123.
I got the remedy
Originariamente inviato da albgen
come cavolo si fa ?
es,ho una:
string str = "123";
int k;
voglio fare in modo che k abbia il il valore 123.
codice:k=atoi(str);
01010011 01100001 01101101 01110101 01100101 01101100 01100101 01011111 00110111 00110000
All errors are undocumented features waiting to be discovered.
visto che sono in tema,l'inverso come si fa ?
ps:itoa(..) non mi funziona
I got the remedy
Se correttamente implementata funziona :-)Originariamente inviato da albgen
visto che sono in tema,l'inverso come si fa ?
ps:itoa(..) non mi funziona
Nota dall' help del BCC32 :codice:int number = 12345; char string[25]; itoa(number, string, 10); printf("integer = %d string = %s\n", number, string);
/**
* Header File
* stdlib.h
*
* Category Conversion Routines, Math Routines
*
* Syntax :
*
* #include <stdlib.h>
* char *itoa(int value, char *string, int radix);
* wchar_t *_itow(int value, wchar_t *string, int radix);
*
* Description :
*
* Converts an integer to a string.
*
* itoa converts value to a null-terminated string and stores the result in string. With itoa, value is an integer. _itow is the unicode version of the function. It converts an integer to a wide-character string.
*
* radix specifies the base to be used in converting value; it must be between 2 and 36, inclusive. If value is negative and radix is 10, the first character of string is the minus sign (-).
*
* Note: The space allocated for string must be large enough to hold the returned string, including the terminating null character (\0). itoa can return up to 33 bytes.
*
* Return Value
*
* itoa returns a pointer to string.
**/
01010011 01100001 01101101 01110101 01100101 01101100 01100101 01011111 00110111 00110000
All errors are undocumented features waiting to be discovered.
#include <stdio.h>
#include <stdlib.h>
libro.cpp:44: error: `itoa' undeclared (first use this function)
uso g++ 3.3
I got the remedy
Io ho compilato questo senza problemiOriginariamente inviato da albgen
#include <stdio.h>
#include <stdlib.h>
libro.cpp:44: error: `itoa' undeclared (first use this function)
uso g++ 3.3
Forse il tuo non è installato correttamente. :master:codice:// Compilabile con BCC32 (v5.5) // E con MinGW32-GCC-3.4.2 (g++.exe) #include <stdlib.h> #include <stdio.h> #include <conio.h> int main() { int number = 12345; char string[25]; itoa(number, string, 10); printf("integer = %d string = %s\n", number, string); printf("%i", atoi("123") ); getch(); return 0; }
01010011 01100001 01101101 01110101 01100101 01101100 01100101 01011111 00110111 00110000
All errors are undocumented features waiting to be discovered.
il g++ del mingwin non è lo stesso del g++ del http://gcc.gnu.org.
ho trovato questa pagina http://www.cplusplus.com/ref/cstdlib/
in fondo c'è scritto:
* = not ANSI-C, but supported by most compilers.
probabilmente il gcc non è 100% ansi-c
I got the remedy
Proprio lo stesso no... Ma in pratica...Originariamente inviato da albgen
il g++ del mingwin non è lo stesso del g++ del http://gcc.gnu.org.
Che io sappia non esiste ancora un compilatore 100% ansi-c !ho trovato questa pagina http://www.cplusplus.com/ref/cstdlib/
in fondo c'è scritto:
* = not ANSI-C, but supported by most compilers.
probabilmente il gcc non è 100% ansi-c
Parziale soluzione : Installa il MinGW
Oppure potresti ripiegare con questo :
codice:char str[10]; int val=123; sprintf(str, "%d", val); printf("%s", str);
01010011 01100001 01101101 01110101 01100101 01101100 01100101 01011111 00110111 00110000
All errors are undocumented features waiting to be discovered.
il mingw l'ho installato ma il progetto che stò facendo, deve compilare con gcc 3.3. ti posso garantire che se provo lo stesso codice con mingw mi vengono furoi un centinaio di errori..invece il viceversa no, cioè se ho un codice scritto con ming e lo compilo con gcc allora va tutto bene..non sò perchè succede questo, ma è cosi'.
grazie.
I got the remedy