Print 1 to 100 in C++ without using loops and recursion
class CPrintNum
{
public: static int iNum;
CPrintNum()
{
cout << iNum++ << endl;
}
};
int CPrintNum::iNum = 1;
int main()
{
CPrintNum obj[100];
return 0;
}
class CPrintNum
{
public: static int iNum;
CPrintNum()
{
cout << iNum++ << endl;
}
};
int CPrintNum::iNum = 1;
int main()
{
CPrintNum obj[100];
return 0;
}
There are basically four methods to run a command in Visual C++. WinExec is provided only for compatibility with 16-bit Windows. Applications should use the CreateProcess function.
· system(), _wsystem() · ShellExecute() or ShellExecuteEx() · CreateProcess() · WinExec()
To get the name of files in a folder,
call the FindFirstFile function to open a search handle and get information about the first file that the file system find in the folder.
call the FindNextFile function to continue listing files from a previous call to FindFirstFile.
WIN32_FIND_DATA FindFileData;
HANDLE hFind;
TCHAR *FilePathBuff = L"C:RequiredFolder";
hFind = FindFirstFile(FilePathBuff, &FindFileData);
if (hFind == INVALID_HANDLE_VALUE) {
printf(TEXT("FindFirstFile failed (%d)n"), GetLastError());
}
else
{
printf(TEXT("The first file is %sn"), FindFileData.cFileName);
while (FindNextFile(hFind, &FindFileData) != 0)
{
printf(TEXT("The next file is %sn"), FindFileData.cFileName);
} FindClose(hFind);
}
To Enumerate all views of the document the CDocument class provides GetFirstViewPosition and GetNextView member functions to enumerate all views associated with the document. We call view’s OnUpdate function to communicate with them.
void EnumerateViews()
{
//get the position of the first view in the list
//of views associated with the document.
POSITION pos = GetFirstViewPosition();
//terate through all of the document's views.
while (pos != NULL)
{
CView* pView = GetNextView(pos);
//update view
pView->OnUpdate(pSender, lHint, pHint);
}
}
Using xsd.exe which will be install with the Visual studio can be used.
Open Visual Studio Command Prompt and use the following commands
Setting environment for using Microsoft Visual Studio 2010 x86 tools.
C:Program Files (x86)Microsoft Visual Studio 10.0VC>cd C:
C:>xsd CPPData.xml
Microsoft (R) Xml Schemas/DataTypes support utility [Microsoft (R) .NET Framework, Version 4.0.30319.1] Copyright (C) Microsoft Corporation. All rights reserved. Writing file 'C:CPPData.xsd'. C:>xsd CPPData.xsd /classes Microsoft (R) Xml Schemas/DataTypes support utility [Microsoft (R) .NET Framework, Version 4.0.30319.1] Copyright (C) Microsoft Corporation. All rights reserved. Writing file 'C:CPPData.cs'. C:>
using System;
using System.Collections.Generic;
namespace RandomSelect {
class Program {
static List lst = new List();
static void Main(string[] args) {
lst.Add("1");
lst.Add("2");
lst.Add("3");
lst.Add("4");
lst.Add("5");
lst.Add("6");
lst.Add("7");
lst.Add("8");
lst.Add("9");
lst.Add("10");
Random rndElement = new Random();
foreach (string i in lst) {
string s = lst[rndElement.Next(lst.Count)];
Console.WriteLine(s);
}
}
}
}
If you’ve any problems in uninstalling Visual Studio 2008, 2010 from Add/ Remove programs in XP or from Programs and features in Windows 7 you can use Microsoft Visual Studio 2008 Auto uninstall utility to remove Visual Studio 2008 and Visual Studio 2010 Auto uninstall utility to remove Visual Studio 2010 editions from your Computer .
# include <iostream>
using namespace std;
int main() {
int a=10,b=2;
b = a+++a;
cout<<b<<" "<<a<<"n";
return 0;
}
OUTPUT 20 11
Step by Step tutorial for creating Simple WPF Application
FAQ-1
void main() {
int _p = 91; //compilation error
printf("%d n",_ p);
printf("%d n", p);
}
OUTPUT: Does not compile error C2440: 'initializing' : cannot convert from 'int' to 'int *'
FAQ-2
void main() {
int i = 91; int *p = &i;
printf("%d n", *p); printf("%d n", p);
}
OUTPUT: 91 1245024
FAQ-3
void main() {
int i = 91;
int *p = &i;
printf(" p = %d n",p);
printf(" p = %d n", p);
printf(" &p = %d n", &p);
printf(" (&p) = %d n", (&p));
printf(" ((&p)) = %d n", ((&p)));
}
OUTPUT: i = 91 &i = 1245024 p = 91 p = 1245024 &p = 1245012 (&p) = 1245024 ((&p)) = 91
FAQ-4
void main() {
const int p;
int i;
i = 10;
p = &i;
printf("p = %d, p = %d, i = %d", p, p, i);
}
OUTPUT p = 1245012, p = 10, i = 10