I'm making a small form with Qt, I insert several QPushButton buttons, but I don't have to add the header that specifies it, nor is anything added in the .cpp or .h files, but it works perfectly. Is the library included within another? In which?
Jogofus's questions
I am trying to make a windows form, and researching the web, I have seen that it is the c++/cli language, but I do not understand very well what this means. As I understand it, it is a modification of c++ by Windows, but I don't see any kind of relationship with the standard language, since if I want to print by console in c++ I would use std::cout << "Hola mundo"
and in c++/cli it would beConsole::WriteLine("Hola Mundo");
Why, if it has such a different syntax, is it considered part of the same language (an extension or a modification)?
What is the difference between adding a return -1 and a return 1 to any function of type int? Reading the code of a program that was circulating on a forum, in some functions it used return -1 and in others it used return 1.
Well, I'm developing a web page, and I have something similar to this:
HTML
<section>
<article class="first">
<!-- Resto de estructura -->
</article>
<article class="second">
<!-- Resto de estructura -->
</article>
</section>
CSS:
.first{
width: 100%;
height: 300px;
background-color:blue;
position: relative;
top: 100px;
}
.second{
width: 100%;
height: 300px;
background-color:red;
}
The problem is that the article first overlaps on top and they don't follow the correct flow. I thought this happened when using position: absolute...
I am trying to study how to connect a program (in terminal) in C++ with a database. At first it doesn't matter what type of database it is (if MySQL, .mdb). I've searched everywhere and can't find a solution. What I see the most is how to connect it through visual studio, and I don't use it for anything, only Sublime. Where can I find any reference/guide/documentation about this?
I am trying to run this code:
<style type="text/css">
#boton{
width: 50px;
height: 30px;
display: block;
margin:30px;
}
img{
width: 300px;
height: 200px;
margin:30px;
}
</style>
<script type="text/javascript">
var boton = document.getElementById('boton');
boton.onclick = function(){
var imagen = document.getElementById('foto');
imagen.style.display ='none';
}
</script>
</head>
<body>
<button id="boton">Click</button>
<img src="header.jpg" id="foto">
</body>
The problem is that it doesn't load the event onclick
in any way. I have also tried to create the function before and call it when the event happens, but it doesn't work. The only way that works for me is by entering the code inline, and I don't want to do it that way. The idea is to make all the javascript code in a separate file.
Comparing the two file stream libraries such as cstdio and fstream I conclude that they do exactly the same thing. I am studying C++. Is it better to continue with the "evolution" of the language and continue with fstream? The only thing that I think is different is that in cstdio there are the rename and remove functions to rename and delete files. Can this also be done with fstream?
I am trying to read a .txt file using C++, in which the user enters (in this case a "user" and a "pass") two pieces of information, and when they are compared, if both are present, a type " Correct login". The code is the following:
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
int main(){
ifstream archivo("user.txt");
//Obtencion de datos
cout << "Usuario: ";
char user[25];
cin.getline(user,25,'\n');
cout << "Pass: ";
char pass[25];
cin.getline(pass,25,'\n');
//Creacion de la linea a buscar
char busqueda[100];
strcpy(busqueda, user);
strcat(busqueda, " ");
strcat(busqueda, pass);
char linea[100];
while(!archivo.eof() || busqueda != linea){
for(int i = 0; i!=archivo.eof(); i++){
archivo.getline(linea, 100);
}
}
cout << endl << endl << "LOGIN CORRECTO." << endl << linea;
return 0;
}
The problem is that once you enter the two data, you get stuck in an infinite loop where you do nothing. You can be giving it an intro all the time it doesn't come out of there...
Doing more tests, I have arrived at the following code. The only thing is that it only compares with the first line of the file.
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
struct registro{
string name;
string second;
string street;
string user;
string pass;
} usuario;
void registroUsuario(){
ofstream archivo("registro.txt");
archivo << "----------------------" << endl;
archivo << "Nombre: " << usuario.name << endl;
archivo << "Apellido: " << usuario.second << endl;
archivo << "Direccion: " << usuario.street << endl;
archivo << "Usuario: " << usuario.user << endl;
archivo << "Password: " << usuario.pass << endl;
archivo.close();
}
void registroLogin(){
ofstream archivo("usuarios.txt");
archivo << usuario.user;
archivo << " ";
archivo << usuario.pass;
archivo << "\n";
archivo.close();
}
bool login(string usuario, string password){
ifstream archivo("usuarios.txt");
string busqueda = usuario + " " + password;
string linea;
while(!archivo.eof()){
getline(archivo, linea);
if(linea == busqueda){
return true;
}
else{
return false;
}
}
}
int main(){
menu:
cout << "\t\t\t *** Base de datos ***" << endl << endl;
cout << "1. Registro de usuario" << endl;
cout << "2. Login" << endl;
cout << "0. Salir" << endl << endl;
cout << "Escoge una opcion: ";
int option;
cin >> option;
cin.ignore();
cout << endl << endl;
system("pause");
switch(option){
case 1:{
system("cls");
cout << "Nombre: ";
getline(cin, usuario.name);
cout << endl << "Apellido: ";
getline(cin, usuario.second);
cout << endl << "Direccion: ";
getline(cin, usuario.street);
cout << endl << endl << "Nombre de usuario: ";
getline(cin, usuario.user);
cout << endl << "Password: ";
getline(cin, usuario.pass);
registroUsuario();
registroLogin();
cout << endl << endl;
system("pause");
goto menu;
break;
}
case 2:{
system("cls");
cout << "Usuario: ";
getline(cin, usuario.user);
cout << endl << "Password: ";
getline(cin, usuario.pass);
if(login(usuario.user, usuario.pass) == true){
goto login;
}
else{
cout << endl << endl << "Login incorrecto.";
goto menu;
}
break;
}
}
login:
cout << endl << endl << endl << "LOGIN CORRECTO";
return 0;
}
I'm browsing the sstream library and I've come across stringstream. Googling I come to the conclusion that it is the same as string, but I can't understand it.
As I understand it, it is to create a string and use it as "cin" to concatenate?
#include <string> // std::string
#include <iostream> // std::cout
#include <sstream> // std::stringstream
int main () {
std::stringstream ss;
ss << 100 << ' ' << 200;
int foo,bar;
ss >> foo >> bar;
std::cout << "foo: " << foo << '\n';
std::cout << "bar: " << bar << '\n';
return 0;
}
When saving a piece of data, whatever its type, what advantages does input have over sys.stdin and/or vice versa? From what I understand, the result is the same.
I am informing myself with the functions to interact with the user. I'm with the basics: raw_input()
e input()
. I have read that it input()
only takes integer data, that it does not accept strings, and that for this we use raw_input()
.
The problem is that if I store a string in a variable with input()
if it accepts it and recognizes it. But if I try to do the same with raw_input()
it gives me the following error:
Traceback (most recent call last): File "lllll.py", line 9, in <module> raw_input() NameError: name 'raw_input' is not defined
I work with Python 3.5.2
What is the difference in C++ between a structure and a class? From what I understand, a struct is the c++ way of creating an object, just like python uses class.
I am not very clear about the difference between the cstring library and the string library. As I understand it, the string header is, as its name suggests, for string types, while cstring is for using its char-typed functions.
I am now with conditional statements and logical operators, and the following problem arises.
If I have the following code:
string deporte;
cout << "Indica tu deporte favorito: ";
cin.get();
getline(cin, deporte);
if (deporte == "futbol" || deporte = "baloncesto")
cout << "Te gustan los deportes de equipo" << endl;
else
cout << "Lo tuyo son los deportes individuales" << endl;
The fact is that this way it does execute correctly, but if on the contrary I delete cin.get()
, the program goes directly to else
without giving the user the option to enter the data.
What am I doing wrong?
Thanks.
I'm getting started with C++ programming and I have to say that it's one of the few programming languages that I really liked.
Now I am with the subject of data entry by the user, but I have a question, since in some sites I see that they use "cin >> "
and in others they use cin.getline()
.
What is the difference between them?
Which is better?