On-line: гостей 0. Всего: 0 [подробнее..]
Программисты всех стран, объединяйтесь!

АвторСообщение



ссылка на сообщение  Отправлено: 28.10.14 06:43. Заголовок: undo function


hi

how can i initialize 3d vector in c++98 i am using visual studio 2010
i am wondering how undo is working in software's how can i code a basic undo function in c++

Спасибо: 0 
ПрофильЦитата Ответить
Ответов - 2 [только новые]





ссылка на сообщение  Отправлено: 28.10.14 19:17. Заголовок: MS C++ 2010 supports..


MS C++ 2010 supports some intermediate C++ between C++ 2003 and C++ 2011. For example it supports lambda expressions.

Howeve MS VC++ 2010 does not support initializer lists. Thus you may not for example write
 
std::vector<int> v = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };


However the similar result can be obtained in MS VC++ 2010 using standard algorithm std::iota declared in header <numeric>:
 
#include <numeric>

//...

std::vector<int> v( 10 );

std::iota( v.begin(), v.end(), 0 );


If you would use a compiler that supports C++ 2011 then you could initialize a "multidimensional" vector for example the following way using initializer lists.
 
#include <iostream>
#include <vector>

int main()
{
std::vector<std::vector<std::vector<int>>> v =
{
{
{ 1, 2, 3, },
{ 4, 5, 6, }
},
{
{ 7, 8, 9, },
{ 0, 1, 2, }
}
};

for ( const auto &v1 : v )
{
for ( const auto &v2 : v1 )
{
for ( int x : v2 ) std::cout << x << ' ';
std::cout << std::endl;
}
std::cout << std::endl;
}

return 0;
}


You can not do the same using MS VC++ 2010. You should use some approach with loops and/or algorithms. For example
 
#include "stdafx.h"
#include <iostream>
#include <vector>
#include <algorithm>

int _tmain(int argc, _TCHAR* argv[])
{
std::vector<std::vector<std::vector<int>>> v( 2 );

for ( std::vector<std::vector<std::vector<int>>>::size_type i = 0; i < v.size(); i++ )
{
const size_t N = 2;
const size_t M = 3;

struct value
{
int a[N][M];
} init;

if ( i == 0 )
{
value tmp =
{
{
{ 1, 2, 3, },
{ 4, 5, 6, }
}
};

init = tmp;
}
else
{
value tmp =
{
{
{ 7, 8, 9, },
{ 0, 1, 2, }
}
};

init = tmp;
}
std::transform( std::begin( init.a ), std::end( init.a ), std::back_inserter( v ),
[]( const int ( &row )[M] )
{
return std::vector<int>( std::begin( row ), std::end( row ) );
} );
}

for each ( const auto &v1 in v )
{
for each ( const auto &v2 in v1 )
{
for each ( int x in v2 ) std::cout << x << ' ';
std::cout << std::endl;
}
std::cout << std::endl;
}

return 0;
}


The output is
 
1 2 3
4 5 6

7 8 9
0 1 2




Спасибо: 0 
ПрофильЦитата Ответить



ссылка на сообщение  Отправлено: 28.10.14 19:18. Заголовок: As for undo then I c..


As for the undo command then I can say nothing. It depends on the application itself.

Спасибо: 1 
ПрофильЦитата Ответить
Ответ:
1 2 3 4 5 6 7 8 9
большой шрифт малый шрифт надстрочный подстрочный заголовок большой заголовок видео с youtube.com картинка из интернета картинка с компьютера ссылка файл с компьютера русская клавиатура транслитератор  цитата  кавычки моноширинный шрифт моноширинный шрифт горизонтальная линия отступ точка LI бегущая строка оффтопик свернутый текст

показывать это сообщение только модераторам
не делать ссылки активными
Имя, пароль:      зарегистрироваться    
Тему читают:
- участник сейчас на форуме
- участник вне форума
Все даты в формате GMT  3 час. Хитов сегодня: 3
Права: смайлы да, картинки да, шрифты да, голосования нет
аватары да, автозамена ссылок вкл, премодерация откл, правка нет