• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Learning C/C++ - Tutorial

I dunno how to use puts although I think I'm gonna have to learn it next month when I start doing Form Applications in college.



Of course, I know both VS 2008 and 2010 have IntelliSense. What I mean is that compared to VS2008, VS2010 doesn't have a drop-down function list. The way IntelliSense works in VS2010 is more like for tracking errors, not autocomplete like VS2008.

2010s intelliSense can do everything that 2008s can do.. if you want a list of available functions hit control space.. control space is like the auto complete hot key

Maybe you could provide a concrete example where 2010's intellisense fails comparison to 2008?
 
2010s intelliSense can do everything that 2008s can do.. if you want a list of available functions hit control space.. control space is like the auto complete hot key

Maybe you could provide a concrete example where 2010's intellisense fails comparison to 2008?

Ok. Especifically, IntelliSense's autocomplete function doesn't work in VS2010 with C++ projects and it even shows a message at the lower left corner saying "Visual C++ 2010 does not have IntelliSense for C++/CLI.". Apparently the support for it was reduced because of time and resource constraints.

Using puts is simple, but just abit faster than printf, and using it when there's no need for formatting, i.e:
[cpp]puts("hello world");[/cpp]
makes more sense than:
[cpp]printf("hello world\n");[/cpp]
see: c++ - mixing cout and printf for faster output - Stack Overflow
As long as it isn't the same case as system("cls") and Console::Clear where the first one uses more resources to go faster, it's ok lol.
 
Ok. Especifically, IntelliSense's autocomplete function doesn't work in VS2010 with C++ projects and it even shows a message at the lower left corner saying "Visual C++ 2010 does not have IntelliSense for C++/CLI.". Apparently the support for it was reduced because of time and resource constraints.


As long as it isn't the same case as system("cls") and Console::Clear where the first one uses more resources to go faster, it's ok lol.
And yes intellisense is depreciated with CLI but if your doing normal console apps and nothing visual you won't have that problem
They depreciated it because they basicly dropped support for CLI and the intellisense would no longer be up to date (from what i've read atleast)
 
This is the way how I set up a new C++ file




STEP 1:
Click "New Project"
iZ_twb.png


STEP 2:
Click "Win32", then click "Win32 Console Application", then come up with the name for the file
7O0skd.png


STEP 3:
Uncheck "Precompiled header" and then check "Empty project"
Eh1nc2.png


STEP 4:
Right click "Source Files" folder to add a new cpp file
prHEre.png


STEP 5:
Select "CPP File" and come up with a name for the file
LsfD4H.png


STEP 6:
Success
9Pf7s.png
 
And yes intellisense is depreciated with CLI but if your doing normal console apps and nothing visual you won't have that problem
They depreciated it because they basicly dropped support for CLI and the intellisense would no longer be up to date (from what i've read atleast)

Now I get it, I forgot to mention I start all my projects with CLR Console Application because most of the things I learned in college needed .Net Framework and well...I kinda got the habit of always starting my projects with the .NET compilation settings on by default. That's why IntelliSense autocomplete doesn't works in my case, but if you're making a Win32 Console Application it will totally work as you say. Also, afaik they are planning to re-add the autocomplete support in CLI in VS2012.
 
Now I get it, I forgot to mention I start all my projects with CLR Console Application because most of the things I learned in college needed .Net Framework and well...I kinda got the habit of always starting my projects with the .NET compilation settings on by default. That's why IntelliSense autocomplete doesn't works in my case, but if you're making a Win32 Console Application it will totally work as you say. Also, afaik they are planning to re-add the autocomplete support in CLI in VS2012.

Your correct on the 2012 inclusion.. although as of right now i don't see a forms application in the CLR section as in 2010.. they give you CLR Console app, Class Lib, and CLR empty project
I'm running the RC version of 2012 they might add forms back into the full version, 2012 is pretty sweet if you haven't checked it out yet.. my favorite addition: they added a drop down for all the files in your project and it will list what functions and classes are in those files

EDIT - you can add forms really easily onto blank apps.. all functionality seems to be returned they definiatly fixed intellisense without a doubt.. might actually start making visual forms in c++ now instead of java.. gotta see how easy it is :)
 
This is the way how I set up a new C++ file




STEP 1:
Click "New Project"
iZ_twb.png


STEP 2:
Click "Win32", then click "Win32 Console Application", then come up with the name for the file
7O0skd.png


STEP 3:
Uncheck "Precompiled header" and then check "Empty project"
Eh1nc2.png


STEP 4:
Right click "Source Files" folder to add a new cpp file
prHEre.png


STEP 5:
Select "CPP File" and come up with a name for the file
LsfD4H.png


STEP 6:
Success
9Pf7s.png

... or you could just make it an empty project to start with ;p.

kHcUE.png
 
Weey! I've started once again after a little break :)

I've messed around a little, but forgot the most. So I am going to start with lesson one.
Updating this soon.
 
Bump.
C++ is better?
Well, it depends on what you're using it for... but C is low-level, I'd recommend escaping the strings part of C explained in this tutorial and jumping right into C++... C is just, hard.

Doing an update soon.
 
Last edited:
why do you use printf? why dont you use cout ?? :eek: ive programmed in 1 year in school but my teacher sucked and i did not learn much from him..
 
#include <stdio.h>
int main() {
printf("Hello world!\n");
return 0;
}
hey dude, why wont use conio.h and getch instead ? well, aint actually sure if u can use them in c, but its certainly available in c++ :p
 
@Repear7 conio.h is a C library
@Jetro Sure, that's easy.

- - - Updated - - -

There you go (It can be even sexier tho :p):
Code:
#include <iostream>  /* I/O Streaming */
#include <stdio.h>
#include <string>    /* C++ string */
#include <errno.h>   /* errror number */
#include <string.h> /* for strerror() */
#include <sys/stat.h>  /* stat() the file */
#include <stdexcept>

class FileException : public std::exception {
public:
	FileException(const std::string& error) throw() { m_error = error + " " + std::string(strerror(errno)); }
	~FileException() throw() { }  /* do nothing */

	const char *what() const throw() { return m_error.c_str(); }
private:
	std::string m_error;
};

class File {
	/// Disable copying and/or assignments
	File(const File& file);
	File& operator=(const File& f);

public:
	enum FileOpenMode {
		OpenRead,
		OpenWrite,
		OpenReadWrite
	};

	File(const std::string& name)
		: m_file(NULL), m_fileName(name)
	{ }

	~File() { close(); }

	void open(File::FileOpenMode _mode) {
		std::string mode;
		switch (_mode) {
			case File::OpenRead:   		mode = "r"; break;
			case File::OpenWrite:  		mode = "w"; break;
			case File::OpenReadWrite: 	mode = "rw"; break;
			default:   /* work around for invalid modes */
				throw FileException("Invalid file open mode");
		}
		m_file = fopen(m_fileName.c_str(), mode.c_str());
		if (!m_file)
			throw FileException("failed to open file");
	}

	void close() {
		if (m_file && fclose(m_file))
			throw FileException("failed to close file");
	}

	void write(const std::string& str, int len = -1) {
		if (len == -1)    len = str.length();
		if (!m_file)
			throw FileException("write() called when file is not open");

		if (fputs(str.c_str(), m_file) != len)
			throw FileException("cannot write to file");
	}

	void read(std::string& str, int len) {
		if (!m_file)
			throw FileException("read() called when file is not open");
		char buff[len+1];
		if (!fgets(buff, len, m_file))
			throw FileException("cannot read from file");
		buff[len] = '\0';
		str = buff;
	}

	int size() {
		struct stat st;
		if (stat(m_fileName.c_str(), &st) != 0)
			throw FileException("cannot stat() the file");
		return st.st_size;
	}

private:
	FILE *m_file;
	std::string m_fileName;
};

int main(int argc, char *argv[]) {
	std::string fname = "hello.txt";
	if (argc > 1)
		fname = argv[1];

	std::clog << "Opening " << fname << std::endl;
	File f(fname);
	f.open(File::OpenRead);

	std::string str;
	f.read(str, f.size());
	std::clog << "read: " << str << std::endl;
	return 0;
}
 
Hiiiii Fallen,

You explain the concept of C language in very easy way ...... I understand that you Explain.
I just read only the Basics of C Language and I am also very excited to read the Part 2 and 3..
I hope i will get lots of information about C Language from Part 2 and 3.......
 
Not until next summer holiday or maybe never, we'll see. ; -)
 
Back
Top