New in Visual Basic C++

Hello all!
I own a bit of experience in C++ PWN and now I decided to learn C++ in Visual Basic.
Like most, I did my first "Hello World" with more few things.
I'm brazilian, so, my strings are in portuguese.
See:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <stdafx.h>
#include <stdio.h>
#include <limits>
#include <iostream>
using namespace std;

void dizeae()
{
	cout << "e aeee\n";
	cout << "Mostra o alfabeto aew lek\n";
	for(char alfabeto = 97; alfabeto <= 122; alfabeto++)
	cout << alfabeto << " ";
}

int main()
{
	dizeae();
	std::cout << "\nPressione ENTER para continuar...";
	std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
	return 0;
}

And I would love to start my journey here in this forum!
My first question is: Where can I find the native functions?
And also I want to know the syntaxes of this language.
Thanks all and I hope I'm welcome!
The newest standard of C++ is C++11 (from 2011). Upcoming in 2014 should be C++14. Keep this in mind, otherwise you might be learning from outdated sources and using outdated tools.

Tutorials and references:
http://www.cplusplus.com/doc/tutorial/
http://www.cplusplus.com/reference/
http://en.cppreference.com/w/
http://www.icce.rug.nl/documents/cplusplus/
http://stdcxx.apache.org/doc/stdlibug/

Tools:
Visual Studio 2012: http://www.microsoft.com/visualstudio/eng/downloads#d-2012-express
Visual Studio 2013 (upcoming): http://www.microsoft.com/visualstudio/eng/2013-downloads
MinGW (commandline): http://nuwen.net/mingw.html
Orwell Dev-C++: http://sourceforge.net/projects/orwelldevcpp/
Ohh thanks! I will keep this in mind!
I use Visual Studio 2010.
I will buy a notebook, so I will can install Visual Studio 2012.
It's Visual Basic C++ 2010 outdated?
Thank you for you response and for the links of the tutorials!
It's Visual Basic C++ 2010 outdated?

I would say yes, if you want to use features of C++11.
It supports C++98, C++03 and some features of C++0x (which grew up as C++11 later).

See these tables:
http://blogs.msdn.com/b/vcblog/archive/2010/04/06/c-0x-core-language-features-in-vc10-the-table.aspx
http://blogs.msdn.com/b/vcblog/archive/2011/09/12/10209291.aspx
http://blogs.msdn.com/b/vcblog/archive/2013/06/28/c-11-14-stl-features-fixes-and-breaking-changes-in-vs-2013.aspx

Even Visual C++ 2012 is missing at least one important feature of C++11: initializer lists.
Visual C++ 2013 should be available by winter this year, hopefully sooner.
Well, I'm doing several things in this Visual C++ 2010.
Like I said, I will install the 2012 in the notebook and as soon the launch 2013, I will get it.
For while, I will learning the functions native.
I already did a calculator and now I'm working on a quiz, to go deeper.
One question: strcmpi don't support spaces?
Like:
(!(strcmpi(str, "Cristovao Colombo")))
If the user tip "Cristovao Colombo" for who was discovered America, it sends the message that is the wrong man.
if((!(strcmpi(str, "Cristovao Colombo"))) || (!(strcmpi(str, "Colombo"))))
Don't have support for spaces? Oh, and console also do not support accents, right? My language needs.
A hug.
Last edited on
Firstly, strcmpi() is not a standard function.

This means that it's not officially part of the C++ standard, and therefore the code you write using strcmpi() may not compile for other people who use other tools than you do.

For example if I don't use Visual C++ but I use MinGW, then maybe I will not be able to compile your code.

If you want to be a Windows programmer only, you may just was well use MSDN to learn C++, and use non-standard functions and extensions.

Otherwise, only use functions which appear in Standard C++ references:
http://www.cplusplus.com/reference/
http://en.cppreference.com/w/

Secondly, a little history lesson.

Before C++ there was C.
Today C and C++ exist as two different but related languages, and over the years they borrowed features from one another.

Because C++ is based on C, it inherited a part of the library of C (headers, functions).
At the same time, C++ added new libraries as a better alternative to those from C.

As a C++ programmer, you should generally avoid using the legacy libraries inherited from C.

In your case, learn to use std::string and the algorithm library of C++ instead of the string.h library of C.

Thirdly, accents should be supported if you use wide character types: std::wstring, std::wcin, std::wcout etc.
As for the spaces problem, you're probably using std::cin which stops reading user input after the first space it finds. Use std::getline() instead.

If you want to compare strings without case sensitivity, you have a lot of work to do:
http://stackoverflow.com/questions/11635/case-insensitive-string-comparison-in-c
http://www.gotw.ca/gotw/029.htm

I tried writing a program to deal with accents, but I am using only MinGW currently, and the program doesn't work correctly.

Maybe in Visual Studio 2012 it may work? And maybe someone else can help more (maybe you must use the locale library)?
http://msdn.microsoft.com/en-us/library/39cwe7zf.aspx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// This is C++11 code.

#include <iostream>
#include <string>

int main()
{
    const std::wstring expected_name(L"Cristóvão Colombo");
    std::wstring given_name;

    std::wcout << "Question: Who discovered America?\nYour answer: ";
    std::getline(std::wcin, given_name);

    if (given_name != expected_name)
        std::wcout << "Your answer was wrong. It was " << expected_name << ".\n";
    else
        std::wcout << "Your answer was correct!\n";
}

Before C++ there was C.
Today C and C++ exist as two different but related languages, and over the years they borrowed features from one another.
I know.

In your case, learn to use std::string and the algorithm library of C++ instead of the string.h library of C.
I will continue to study and adapt the most innovative tools of C++ 14.

I tried writing a program to deal with accents, but I am using only MinGW currently, and the program doesn't work correctly.
Really, accents in the console are a problem.
We can understand well without accents, but gets weird.
And I'm using goto. I know is outdated, but works fine.
I'm working in a quiz. And I will use ur example with std.
Thank you.
@EDIT
Don't worked for me.
See my code:
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include <stdio.h>
#include <stdafx.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <sstream>
using namespace std;

bool impedido;
int pontos;

int main()
{
	impedido == true;
	pontos = 0;
	char str[70];
	inicio:
	cout << "\n:::::::::::::::::Quiz iniciado!!!!:::::::::::::::::\n";
	cout << "\nRegras:\n";
	cout << "Todas as respostas sao de apenas 1 palavra.\n";
	cout << "A cada resposta certa, voce ganha 1 ponto.\n";
	cout << "Se houver erro, voce tera que comecar novamente.\n";
	quest1:
	cout << "\n1 - Quem descobriu a America?\n";
	scanf("%s", str);
	if((!(strcmpi(str, "Colombo"))))
	{
		cout << "Sim, foi ele mesmo! (+1 ponto)\n";
		pontos++;
		goto quest2;
	}
	else
	{
		cout << "Nao foi esse cara que descobriu a america!\n";
		goto perdeu;
	}
quest2:
	cout << "\n2 - Como se chamavam os rapazes que cuidavam de vacas no velho oeste?\n";
	scanf("%s", str);
	if((!(strcmpi(str, "Cowboy"))) || (!(strcmpi(str, "Cowboys"))))
	{
		cout << "Sim, eles eram chamados de cowboys! (+1 ponto)\n";
		pontos++;
		goto quest3;
	}
	else
	{
		cout << "Que pena! Voce errou! Eles nao se chamavam assim.\n";
		goto perdeu;
	}
	quest3:
	cout << "\n3 - Qual e o posto mais alto do exercito?\n";
	scanf("%s", str);
	if((!(strcmpi(str, "General"))))
	{
		cout << "Isso mesmo! Bom soldado! (+1 ponto)\n";
		pontos++;
		goto quest4;
	}
	else
	{
		cout << "Voce errou! Que tal ir para o quartel e aprender?\n";
		goto perdeu;
	}
	quest4:
	cout << "\n4 - Quem da sua familia tem 17 anos?\n";
	scanf("%s", str);
	if((!(strcmpi(str, "Manoel"))))
	{
		cout << "Na verdade ele vai fazer 17, mas ta certo! (+1 ponto)\n";
		pontos++;
		return EXIT_SUCCESS;
	}
	else
	{
		cout << "Voce errou! Que vergonha nao saber que o gostosao do Manoel tem 17 anos!\n";
		goto perdeu;
	};


//Final se tiver errado
perdeu:
	impedido == false;
	printf("\nResposta errada. Fim do quiz. Seus pontos totais: %d\n", pontos, str);
	cout << "\nRecomecar? [Sim/Nao]\n";
	soun:
		scanf("%s", str);
		if((!(strcmpi(str, "Sim"))) && impedido == false)
		{
			pontos = 0;
			goto inicio;
		}
		else if((!(strcmpi(str, "Nao"))) && impedido == false)
		{
			pontos = 0;
			return EXIT_SUCCESS;
		}
		else
		{
			cout << "Digite Sim ou Nao: ";
			goto soun;
		}
//
}

If you want to understand something, use:
http://translate.google.com.br/?hl=pt-BR&tab=wT#pt/en/
Last edited on
Topic archived. No new replies allowed.